Third Light Developer Exchange

Code and templating community forum for developers and software integrators

You are not logged in.

Announcement

If you wish to join the Developer Exchange, please contact your account manager - this is to avoid unnecessary spam in the forums. Many thanks for your understanding.

#1 2021-07-06 20:28:23

ccq
Member
Registered: 2021-07-06
Posts: 4

(401) Unauthorized - Asp.Net

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

#2 2021-07-08 13:53:33

dominic
Third Light Staff
Registered: 2013-06-06
Posts: 119

Re: (401) Unauthorized - Asp.Net

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

#3 2021-07-08 15:50:55

ccq
Member
Registered: 2021-07-06
Posts: 4

Re: (401) Unauthorized - Asp.Net

Hi Dominic,

Thanks for your assistance on this.
Sorry, I had typo here. The code in my application does not have semicolon.

Cham

Offline

#4 2021-07-08 16:36:18

dominic
Third Light Staff
Registered: 2013-06-06
Posts: 119

Re: (401) Unauthorized - Asp.Net

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

#5 2021-07-16 23:42:36

ccq
Member
Registered: 2021-07-06
Posts: 4

Re: (401) Unauthorized - Asp.Net

Thanks Dominic.

You are right. I didn't have the session value correctly in the header.
It has been resolved.

Chamroeun

Offline

Board footer