I’m trying to call IBM Watson’s API to perform sentiment analysis from my Unity project, using the WWW library. This is my current code:
string uri = "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27";
WWWForm form = new WWWForm();
form.AddField ("text", "That%20was%20simply%20magnificent!");
form.AddField ("features", "sentiment");
var headers = form.headers;
byte[] rawData = form.data;
headers["Authorization"] = "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(USERNAME + ":" + PASSWORD));
WWW www = new WWW(uri, rawData, headers);
yield return www;
where USERNAME
and PASSWORD
are my API credentials. However, this code keeps giving me a 415 error. Also, if I change Authorization
to Authentication
, the error changes to 401. I’ve tried making the same request using hurl.it (which works), and I’ve printed out the authorization header and compared it to what hurl.it constructs given a username and password, and they’re the same string - yet the request fails in the project. What am I missing?