hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Error Receiving Session Cookie
Date Tue, 08 Feb 2005 22:29:15 GMT
Mayhew,

Try masquerading HttpClient as a popular browser of your choice (IE for
instance) and see if that makes any difference

GetMethod authget = new GetMethod("/");  
authget.setRequestHeader("User-Agent", 
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");


Oleg

On Tue, 2005-02-08 at 12:32 -0800, Mayhew Seavey wrote:
> I am trying to use HTTPClient to browse the site
> "www.allmusic.com", and it seems to be having trouble
> getting a session cookie when it first enters the
> site.
> 
> I've used IE and Mozilla, first clearing all the
> site-related cookies, and then going to the site,
> confirming that on loading of the home page, a single
> cookie is created.
> 
> Then I used the HTTPClient to load the site with the
> code below, and it doesn't register any cookies having
> been loaded.
> 
> I need to have this cookie in order to go to other
> sections of the site. The code and wire trace are
> below.
> 
> Any help would be greatly appreciated!
> 
> Thanks,
> Mayhew
> 
> ====================
> 
> HttpClient client = new HttpClient();
>        
> client.getHostConfiguration().setHost(LOGON_SITE,
> LOGON_PORT, "http");
>        
> client.getState().setCookiePolicy(CookiePolicy.NETSCAPE_DRAFT);
>      	// 'developer.java.sun.com' has cookie
> compliance problems
>         // Their session cookie's domain attribute is
> in violation of the RFC2109
>         // We have to resort to using compatibility
> cookie policy
> 
>         GetMethod authget = new GetMethod("/");
> 
>         client.executeMethod(authget);
>         System.out.println("Login form get: " +
> authget.getStatusLine().toString()); 
>         // release any connection resources used by
> the method
>         authget.releaseConnection();
>         // See if we got any cookies
>         CookieSpec cookiespec =
> CookiePolicy.getDefaultSpec();
>         Cookie[] initcookies = cookiespec.match(
>             LOGON_SITE, LOGON_PORT, "/", false,
> client.getState().getCookies());
>         System.out.println("Initial set of cookies:");
>    
>         if ((initcookies == null) ||
> (initcookies.length == 0)) {
>             System.out.println("None");    
>         } else {
>             for (int i = 0; i < initcookies.length;
> i++) {
>                 System.out.println("- " +
> initcookies[i].toString());    
>             }
>         }
> 
> =======================
> 
> Wire trace:
> 
> 2005/02/08 15:11:41:734 EST [DEBUG] HttpMethodBase -
> Execute loop try 1
> 2005/02/08 15:11:41:750 EST [DEBUG] header - >> "GET /
> HTTP/1.1[\r][\n]"
> 2005/02/08 15:11:41:750 EST [DEBUG] HttpMethodBase -
> Adding Host request header
> 2005/02/08 15:11:41:750 EST [DEBUG] header - >>
> "User-Agent: Jakarta Commons-HttpClient/2.0.2[\r][\n]"
> 2005/02/08 15:11:41:750 EST [DEBUG] header - >> "Host:
> www.allmusic.com[\r][\n]"
> 2005/02/08 15:11:41:750 EST [DEBUG] header - >>
> "[\r][\n]"
> Login form get: HTTP/1.0 200 OK
> 2005/02/08 15:11:42:140 EST [DEBUG] header - <<
> "HTTP/1.0 200 OK[\r][\n]"
> 2005/02/08 15:11:42:140 EST [DEBUG] header - <<
> "Content-Type: text/html[\r][\n]"
> 2005/02/08 15:11:42:140 EST [DEBUG] header - <<
> "Content-Length: 22834[\r][\n]"
> 2005/02/08 15:11:42:140 EST [DEBUG] header - <<
> "Content: [\r][\n]"
> 2005/02/08 15:11:42:296 EST [DEBUG] HttpMethodBase -
> Resorting to protocol version default close connection
> policy
> 2005/02/08 15:11:42:296 EST [DEBUG] HttpMethodBase -
> Should close connection, using HTTP/1.0.
> 
> 
> 
> 		
> __________________________________ 
> Do you Yahoo!? 
> The all-new My Yahoo! - Get yours free! 
> http://my.yahoo.com 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> 


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


Mime
View raw message