commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Gustavo Zagato <jose.gust...@emacdigital.com.br>
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();
	
initialState.setCookiePolicy(CookiePolicy.COMPATIBILITY);

		HttpMethod method = new GetMethod(server);

		try {

			//Cookie jSession = new
Cookie(domain,"Cookie","JSESSIONID="+sessionId);
			//CookieSpecBase cookspec = new
CookieSpecBase(); 

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

			requestCode = client.executeMethod(method);

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

		} catch (Exception e) {
			e.printStackTrace();

		} catch (Throwable tre) {
			tre.printStackTrace();
		}

		byte[] responseBody = method.getResponseBody();

		return new String(responseBody);

	}

Regards !

  José Gustavo Zagato Rosa
System Analyst - Atos Origin
jose.gustavo@emacdigital.com.br


-----Original Message-----
From: olegk@bluewin.ch [mailto:olegk@bluewin.ch] 
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
session.
Currently HttpClient overwrites manually set 'Cookie' headers. You are
not
the first one to have fallen into this trap. Quite a few people
complained
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,
is
not likely to make it into our stable 2.0 branch, so I strongly
encourage
to use HttpState class to handle cookies.

Cheers

Oleg


>-- Original Message --
>Reply-To: "Jakarta Commons Users List"
<commons-user@jakarta.apache.org>
>Reply-To: <jose.gustavo@emacdigital.com.br>
>From: José Gustavo Zagato <jose.gustavo@emacdigital.com.br>
>To: "'Jakarta Commons Users List'" <commons-user@jakarta.apache.org>
>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
entry
>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
>jose.gustavo@emacdigital.com.br
> 
> 
> 
>  José Gustavo Zagato Rosa
>System Analyst - Atos Origin
>jose.gustavo@emacdigital.com.br
> 


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




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


Mime
View raw message