-
-
Save vpekar/cbaf7f35c8c33da30b73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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