You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by aruba bulk <bu...@jacquesbotha.net> on 2003/12/22 16:27:28 UTC

cookie question - Sorry : Retrying

Hi there (pls ignore my previous post)

I'm using HttpClient to write a Cactus unit test. I'd
like to simulate a browser, sending a cookie to the
server with a request. So the cookie originates at the
client side :

HttpClient client = new HttpClient();
HttpMethod method = new getMethod(url);
String cookieValue = "testValue";
String cookieName = "testname";
Cookie cookie = new Cookie("localhost", cookieName,
cookieValue);
cookie.setPath("/");

HttpState httpState=new HttpState();
httpState.addCookie(cookie);
client.setState(httpState);

// Execute the method.
int statusCode = -1;
try {
  statusCode = client.executeMethod(method);
} catch (HttpRecoverableException e) {} 
  catch (IOException e) {}

// Read the response body.
byte[] responseBody = method.getResponseBody();

My question is this : I need to check whether the
server has set any additional cookies in the response.
How do i do this ? 

Any help greatly appreciated.

Regards
Jacques



=====
"All one's life is music, if one touches the notes rightly, and in time."
    - John Ruskin

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


Re: cookie question - Sorry : Retrying

Posted by Michael Becke <be...@u.washington.edu>.
Hi Jacques,

HttpClient automatically processes cookie in the response and adds any 
new cookies to the associated HttpState.  Take a look at 
HttpClient.getState() and HttpState.getCookies().  There is also some 
more info on cookie parsing at 
<http://jakarta.apache.org/commons/httpclient/cookies.html>.  You can 
also get the raw cookie headers from a response by calling 
HttpMethod.getResponseHeader("Set-Cookie") on the executed method.

Mike

On Dec 22, 2003, at 10:27 AM, aruba bulk wrote:

> Hi there (pls ignore my previous post)
>
> I'm using HttpClient to write a Cactus unit test. I'd
> like to simulate a browser, sending a cookie to the
> server with a request. So the cookie originates at the
> client side :
>
> HttpClient client = new HttpClient();
> HttpMethod method = new getMethod(url);
> String cookieValue = "testValue";
> String cookieName = "testname";
> Cookie cookie = new Cookie("localhost", cookieName,
> cookieValue);
> cookie.setPath("/");
>
> HttpState httpState=new HttpState();
> httpState.addCookie(cookie);
> client.setState(httpState);
>
> // Execute the method.
> int statusCode = -1;
> try {
>   statusCode = client.executeMethod(method);
> } catch (HttpRecoverableException e) {}
>   catch (IOException e) {}
>
> // Read the response body.
> byte[] responseBody = method.getResponseBody();
>
> My question is this : I need to check whether the
> server has set any additional cookies in the response.
> How do i do this ?
>
> Any help greatly appreciated.
>
> Regards
> Jacques
>
>
>
> =====
> "All one's life is music, if one touches the notes rightly, and in 
> time."
>     - John Ruskin
>
> ---------------------------------------------------------------------
> 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