public string GetResponseString(AnalyzeCommentRequest request) { var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); var response = Client.PostAsync(BaseAddress, content).Result; response.EnsureSuccessStatusCode(); return(response.Content.ReadAsStringAsync().Result); }
public AnalyzeCommentResponse QueryToxicity(string input) { var requestedAttributeses = new Dictionary <string, RequestedAttributes> { { "TOXICITY", new RequestedAttributes() } }; var req = new AnalyzeCommentRequest(input, requestedAttributeses); var res = SendRequest(req); return(res); }
public AnalyzeCommentResponse sendRequest(AnalyzeCommentRequest request) { using (var client = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); var response = client.PostAsync(URL, content).Result; response.EnsureSuccessStatusCode(); var data = response.Content.ReadAsStringAsync().Result; var result = JsonConvert.DeserializeObject <AnalyzeCommentResponse>(data); return(result); } }