- Home /
Unable to call external API (IBM Watson) via HTTP request?
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?
Comment
Best Answer
Answer by mxran · Feb 16, 2018 at 09:22 PM
Kind of late, but I ended up just using Watson's Unity SDK (which I didn't know existed).