Esempio n. 1
0
        private static async Task <JObject> RequestService(string apiKey, string apiUri, TextInput query)
        {
            var client      = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
            var uri = apiUri + "?" + queryString;

            var byteData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(query));

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await client.PostAsync(uri, content);

                var contentString = await response.Content.ReadAsStringAsync();

                return(JObject.Parse(contentString));
            }
        }
Esempio n. 2
0
 public static async Task <JObject> DetectSentiments(TextInput query)
 {
     return(await RequestService(Config.TextAnalyticsApiKey, Config.DetectSentimentsApiUri, query));
 }