Create a gist now

Instantly share code, notes, and snippets.

@vpekar /GetSentimentClient.cs Secret
Last active Feb 3, 2016

What would you like to do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
namespace dotnet_integration
{
class Program
{
static void Main(string[] args)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("<ACCESS-URL>");
client.DefaultRequestHeaders.TryAddWithoutValidation("<ACCESS-KEY-HEADER>",
"<ACCESS-KEY>");
var text = "The food was great, but the service was slow.";
var parameters = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("text", text),
new KeyValuePair<string, string>("categories", "1"),
new KeyValuePair<string, string>("sentiment", "1"),
new KeyValuePair<string, string>("annotate", "1")
});
var response = client.PostAsync("", parameters).Result;
if (response.IsSuccessStatusCode)
{
var responseBody = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(responseBody);
Console.ReadLine();
}
else
{
Console.WriteLine("Response status code:" + response.StatusCode);
Console.ReadLine();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment