Skip to content

Instantly share code, notes, and snippets.

@vpekar
Last active February 3, 2016 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpekar/cbaf7f35c8c33da30b73 to your computer and use it in GitHub Desktop.
Save vpekar/cbaf7f35c8c33da30b73 to your computer and use it in GitHub Desktop.
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