commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Gustavo Zagato <>
Subject RE: HttpClient Header Problem
Date Thu, 23 Oct 2003 13:29:22 GMT
Hi ! 

	Thanks for the answer !
	This is the piece of code with Im trying to run, Can you
anything else wrong ? If you have any piece of code with this
httpSate.addcookie please send to me !

public String doRequest(String server, String sessionId, String domain)

		HttpClient client = new HttpClient();
		HttpState initialState = new HttpState();

		HttpMethod method = new GetMethod(server);

		try {

			//Cookie jSession = new
			//CookieSpecBase cookspec = new

			//Header hd =
			method.addRequestHeader("Cookie", "JSESSIONID="
+ sessionId);

			requestCode = client.executeMethod(method);

			Cookie[] cookies =
			// Display the cookies
			System.out.println("Return: " + requestCode);
			System.out.println("Present cookies: ");
			for (int i = 0; i < cookies.length; i++) {
				System.out.println(" - " +

		} catch (Exception e) {

		} catch (Throwable tre) {

		byte[] responseBody = method.getResponseBody();

		return new String(responseBody);


Regards !

  José Gustavo Zagato Rosa
System Analyst - Atos Origin

-----Original Message-----
From: [] 
Sent: quinta-feira, 23 de outubro de 2003 09:13
To: Jakarta Commons Users List
Subject: RE: HttpClient Header Problem

Hi José,

Simply use HttpState#addCookie method to add a cookie to the HTTP
Currently HttpClient overwrites manually set 'Cookie' headers. You are
the first one to have fallen into this trap. Quite a few people
about what they see as disappearance of manually set 'Cookie' headers. I
am planning to provide a patch against CVS HEAD soon. The fix, however,
not likely to make it into our stable 2.0 branch, so I strongly
to use HttpState class to handle cookies.



>-- Original Message --
>Reply-To: "Jakarta Commons Users List"
>Reply-To: <>
>From: José Gustavo Zagato <>
>To: "'Jakarta Commons Users List'" <>
>Subject: HttpClient Header Problem
>Date: Thu, 23 Oct 2003 08:44:37 -0300
>Hi Folks !
>      I'm trying to develop an applet with uses the commons httpclient
>to interact with a struts action. I developed a few examples and it
>worked fine, but now I need to somehow make the applet "join" the http
>session started by the browser with loaded the applet. I tried to add a
>Cookie to the request with contains the session id. In another shot I
>tried to add a new header entry with contains the session id.
>Unfortunately all shots went to wrong directions.
>      So does anyone here has a example on how to add a new header
>to a http get request ? There is any thing special that I need to do to
>"join" a already started session ? How deep is the rabbit hole ?
>Cheers !
>  José Gustavo Zagato Rosa
>System Analyst - Atos Origin
>  José Gustavo Zagato Rosa
>System Analyst - Atos Origin

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message