public static async Task <Screen> CallContentModeratorTextAPI(ContentModeratorTextQuery query) { var url = $"{query.Endpoint + "/Screen"}{query.ToQueryString()}"; using (var bingClient = new BingHttpClient(query.SubscriptionKey)) { var content = new StringContent(query.Text, Encoding.UTF8, query.ContentType); var httpResponseMessage = await bingClient.PostAsync(url, content); if (httpResponseMessage.IsSuccessStatusCode) { var responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <Screen>(responseContent)); } else { throw new InvalidOperationException("An error occurred fetching the results from the service"); } } }
public static async Task <EntitiesBatchResultV2dot1> callTextAnalyticsEntityAPI(TextAnalyticsQuery query) { var url = query.TextAnalyticsEndpoint + "/entities"; using (var bingClient = new BingHttpClient(query.TextAnalyticsKey)) { var documents = JsonConvert.SerializeObject(query); var content = new StringContent(documents, Encoding.UTF8, "application/json"); var httpResponseMessage = await bingClient.PostAsync(url, content); if (httpResponseMessage.IsSuccessStatusCode) { var responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <EntitiesBatchResultV2dot1>(responseContent)); } else { throw new InvalidOperationException("An error occurred fetching the results from the service"); } } }
public static async Task <BingVisualSearchResponse> CallVisualSearchAPI(BingVisualSearchQuery query) { var url = ApiEndpoints.VISUAL_SEARCH_URL + "mkt=" + query.Mkt + "&safeSearch=" + query.SafeSearch + "&setLang=" + query.SetLang; byte[] imageBinary = null; using (MemoryStream ms = new MemoryStream()) { query.FileStream.CopyTo(ms); imageBinary = ms.ToArray(); } var boundary = string.Format("batch_{0}", Guid.NewGuid()); var content = new MultipartFormDataContent(boundary) { { new ByteArrayContent(imageBinary), "image", "myimage" } }; var kb = JsonConvert.SerializeObject(BuildKnowledgeRequest(query.Site, null)); content.Add(new StringContent(kb, Encoding.UTF8, "application/json"), "knowledgeRequest"); using (var bClient = new BingHttpClient(query.SearchKey)) { var httpResponseMessage = await bClient.PostAsync(url, content); if (httpResponseMessage.IsSuccessStatusCode) { var responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <BingVisualSearchResponse>(responseContent)); } else { throw new InvalidOperationException("An error occurred fetching the results from the video service"); } } }