You are not logged in.
I am having trouble getting error returned from the server.
"The remote server returned an error: (401) Unauthorized."
I am able to use some other APIs including "https://chorus/rest/v1/auth/login".
The codes is as following.
=============================================
WebRequest myReq = WebRequest.Create("https://chorus/rest/v1/files/65049425109");
//Headers
myReq.Headers.Add("accept","application/json");
myReq.Headers.Add("X-Chorus-Session:","P3AyqF,oUEig5rV30oMwEPL7PfTTr9Zh");
//Error here
WebResponse wr = myReq.GetResponse();
=============================================
Is there anything missing in my code?
Thanks for guidance on this!
Cham
Offline
Hi Cham,
You appear to have a literal colon in the header name.
myReq.Headers.Add("X-Chorus-Session:", "...");
should be
myReq.Headers.Add("X-Chorus-Session", "...");
I'm not sure how your client will behave with this - whether it is attempting to encode the colon and thus using the wrong name, or whether the colon separating the header name and value is effectively being prepended to the session ID string, making the value invalid - either way, a 401 response would be an expected result.
Dominic
Offline
Hi Dominic,
Thanks for your assistance on this.
Sorry, I had typo here. The code in my application does not have semicolon.
Cham
Offline
Hi Cham,
401 definitely indicates a problem with the session header - so if you have checked the header name, the only other place to try is the value.
First, check that this is a session ID returned by a recent call to /rest/v1/auth/login (or /rest/v1/auth/loginWithKey), and that no logout call has been made.
Second, use a local diagnostic tool to capture the actual HTTP request being made - check that the headers sent are what you expect from the code. Particularly look out for multiple values in the header, which could result from having more than one Headers.Add call for the same header name.
As a final thing to try, use your browser developer tools to find a session ID for a normal Chorus session created by logging in to the web interface. You are looking for a cookie called 'IMSSESSID', set in the response to a call to api.json.tlx. Having found that, try using it to make an API request in your client - this would help to identify if the issue is coming from your handling of the login response.
Dominic
Offline
Thanks Dominic.
You are right. I didn't have the session value correctly in the header.
It has been resolved.
Chamroeun
Offline