C# C# Streams and Data Processing Streaming Data on the Net Text Analytics API Part 2

Richard Oden
Richard Oden
12,398 Points

400 Bad Request - Not sure what I'm doing wrong

I'm getting a 400 Bad Request error, but not quite sure what I'm doing wrong. I don't think there are any typos in my url or api key. Any ideas?

Here is the relevant part of my GetSentimentResponse method. I have the url and api key stored in variables textAnalyticsUrl and key respectively.

var webClient = new WebClient();
webClient.Headers.Add("Ocp-Apim-Subscription-Key", key);
webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
webClient.Headers.Add(HttpRequestHeader.Accept, "application/json");

string requestJson = JsonConvert.SerializeObject(sentimentRequest);
byte[] requestBytes = Encoding.UTF8.GetBytes(requestJson);
byte[] response = webClient.UploadData(textAnalyticsUrl, requestBytes);
string sentiments = Encoding.UTF8.GetString(response);
sentimentResponse = JsonConvert.DeserializeObject<SentimentResponse>(sentiments);

return sentimentResponse;
Richard Oden
Richard Oden
12,398 Points

To clarify, my url is: https://<resource name here>.cognitiveservices.azure.com/text/analytics/v3.0/sentiment And the key is just copied and pasted from the website