Hi Jacques
Here is code snippet, That might help you
public static void initializeClient(HttpServletRequest request) {
if (httpClient == null)
httpClient = new HttpClient();
httpClient.setConnectionTimeout(3000);
HttpState state = httpClient.getState();
state.setCookiePolicy(CookiePolicy.COMPATIBILITY);
Cookie[] cookies = request.getCookies();//This method call gives all the cookies in
response to the browser request..
}
Thanks
Venkat Burri
-----Original Message-----
From: Michael Becke [mailto:[EMAIL PROTECTED]
Sent: Fri 1/2/2004 8:56 AM
To: Commons HttpClient Project
Cc:
Subject: Re: cookie question - Sorry : Retrying
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:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]