get cookie from response

1,006 views
Skip to first unread message

Lukáš Gemela

unread,
Apr 10, 2013, 9:44:51 AM4/10/13
to rest...@googlegroups.com
Hi guys,


I have a problem to get auth cookie from http response. I'm trying to make something like "session driven REST" - at the first attempt, try to connect without HTTP username and pass - it will fail with 401 - NOT AUTHORIZED. Then, try to send request again with user credentials - it shoud be succesful - and there is a Cookie with session ID hidden in response, which should be used instead of  HTTP base auth. My cookie set command from headers looks like

 Set-Cookie    JSESSIONID=A862CD252DB886DE4CA814758755405E; Path=/RAT/; Secure; HttpOnly

This is a trace from httpfox and I can find this cookie on similar android application which has the same feature.

But I cant see this cookie anywhere in my restsharp response, not in Headers collection, not even in cookie collection, even when HTTP Base authorization succeeded and  I am able to deserialise data from content. Shall I do anything special here?


My HTTP headers:

< HTTP/1.1 401 Unauthorized
< Server: Apache-Coyote/1.1
< Cache-Control: private
< Expires: Thu, 01 Jan 1970 00:00:00 UTC
< Set-Cookie: JSESSIONID=53EF3FE938F894D42203A2803E1A5561; Path=/RAT/; Secure; HttpOnly
< Content-Length: 0
< Date: Wed, 10 Apr 2013 13:41:22 GMT

and if I use HTTP auth:

< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Cache-Control: private
< Expires: Thu, 01 Jan 1970 00:00:00 UTC
< Set-Cookie: JSESSIONID=1B56F62207E309813FEC3ACCEC9D74F1; Path=/RAT/; Secure; HttpOnly
< Content-Type: application/xml
< Content-Language: cs-CZ
< Content-Length: 202
< Date: Wed, 10 Apr 2013 13:44:02 GMT
<




Pete Johanson

unread,
Apr 10, 2013, 10:35:09 AM4/10/13
to rest...@googlegroups.com

Make sure to:
1) use the same RestClient instance
2) Set client.CookieContainer = new CookieContiner() to make sure the same container is used for all requests from that client instance.

Does that help?
-pete

--
You received this message because you are subscribed to the Google Groups "RestSharp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to restsharp+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Lukáš Gemela

unread,
Apr 10, 2013, 12:39:15 PM4/10/13
to rest...@googlegroups.com
Ok I know where the problem is...every incoming cookie must have a "Domain" key set up, otherwise it will not work on WP7 device. So I have reconfigured my tomcat settings and now I can see cookie as a header with "set-cookie" key. It´s still missing in CookieContainer but I can parse it manually from header list and push it with next requests as

   request.AddParameter(service.sessionCookie.Name, service.sessionCookie.Value, ParameterType.Cookie);




Dne středa, 10. dubna 2013 14:35:09 UTC Pete Johanson napsal(a):
Reply all
Reply to author
Forward
0 new messages