Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRichard Oden
15,350 Points400 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
15,350 PointsRichard Oden
15,350 PointsTo 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