You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by D Alvarado <la...@wildmail.com> on 2003/11/03 22:37:01 UTC

reading cookies

Hello,
   I was wondering how to use HttpClient classes
and methods to get the value of a cookie.  I want
to fetch the cookie named "SessionID".  How would
I do that?  This is the code I have so far ...

           PostMethod method = new PostMethod(url);
            method.setFollowRedirects(true);    
       
            NameValuePair[] data = {
              new NameValuePair("user", "joe"),
              new NameValuePair("password", "bloggs")
            };
            method.setRequestBody(data);

            // execute request.

            // read response

            String sessionId = ???

            // Release the connection.
            method.releaseConnection();


Thanks for all help, Dave               


Care2 make the world greener!
Help the planet each day! It's free and easy:
http://www.Care2.com/dailyaction/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: reading cookies

Posted by Oleg Kalnichevski <ol...@apache.org>.
Dave, 
Have a look at the the following example:

http://cvs.apache.org/viewcvs.cgi/*checkout*/jakarta-commons/httpclient/src/examples/FormLoginDemo.java?rev=1.1&only_with_tag=HTTPCLIENT_2_0_BRANCH

For more detailed information refer to the Javadoc of the HttpState
class and the CookieSpec interface.  Hope this helps a bit.

http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpState.html
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/cookie/CookieSpec.html
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/cookie/RFC2109Spec.html

Oleg

On Mon, 2003-11-03 at 22:37, D Alvarado wrote:
> Hello,
>    I was wondering how to use HttpClient classes
> and methods to get the value of a cookie.  I want
> to fetch the cookie named "SessionID".  How would
> I do that?  This is the code I have so far ...
> 
>            PostMethod method = new PostMethod(url);
>             method.setFollowRedirects(true);    
>        
>             NameValuePair[] data = {
>               new NameValuePair("user", "joe"),
>               new NameValuePair("password", "bloggs")
>             };
>             method.setRequestBody(data);
> 
>             // execute request.
> 
>             // read response
> 
>             String sessionId = ???
> 
>             // Release the connection.
>             method.releaseConnection();
> 
> 
> Thanks for all help, Dave               
> 
> 
> Care2 make the world greener!
> Help the planet each day! It's free and easy:
> http://www.Care2.com/dailyaction/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org