Right. Now what? So, if a cookie missing, add it. This time around, though, make sure you set a sane expiration date or leave it null for the cookie to never expire. Another imporant detail here is to configure HttpClient to put all the cookies in one cookie header. This may well be the cause of the problem
Calendar calendar = Calendar.getInstance(); // Next Christmas or something calendar.set(2005, Calendar.DECEMBER, 26, 0, 0); Cookie cookie = new Cookie("www.some.com", "SOME_CulturePref", "en-AU", "/", calendar.getTime(), false); HttpClient httpcliet = new HttpClient(); httpcliet.getState().addCookie(cookie); httpcliet.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); httpcliet.getParams().setBooleanParameter(HttpMethodParams.SINGLE_COOKIE_HEADER, true); Hope this helps Oleg On Tue, Dec 14, 2004 at 10:10:20PM +1100, B K wrote: > I have tried the compatibility setting it doesn't work either, here is the > log > > 2004/12/14 21:56:08:312 EST [DEBUG] header - ->> "POST /default.aspx > HTTP/1.1[\r][\n]" > 2004/12/14 21:56:08:312 EST [DEBUG] header - ->> "User-Agent: Jakarta > Commons-HttpClient/3.0-beta1[\r][\n]" > 2004/12/14 21:56:08:312 EST [DEBUG] header - ->> "Host: > www.some.com[\r][\n]" > 2004/12/14 21:56:08:312 EST [DEBUG] header - ->> "Cookie: > ASP.NET_SessionId=drkuf455z50hay550b5eyx45[\r][\n]" > 2004/12/14 21:56:08:312 EST [DEBUG] header - ->> "Content-Length: > 63[\r][\n]" > 2004/12/14 21:56:08:312 EST [DEBUG] header - ->> "Content-Type: > application/x-www-form-urlencoded[\r][\n]" > 2004/12/14 21:56:08:312 EST [DEBUG] header - ->> "[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "HTTP/1.0 500 Internal > Server Error[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "Date: Tue, 14 Dec 2004 > 10:56:00 GMT[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "Server: > Microsoft-IIS/6.0[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "X-Powered-By: > ASP.NET[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "X-AspNet-Version: > 1.1.4322[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "Cache-Control: > private[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "Content-Type: text/html; > charset=utf-8[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "Content-Length: > 3625[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "X-Cache: MISS from > Prolexic.com[\r][\n]" > 2004/12/14 21:56:09:968 EST [DEBUG] header - -<< "Connection: close[\r][\n]" > > I have used to HTTPWatch to look at the request data via IE, it is as > follows > > POST /default.aspx HTTP/1.1 > Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, > application/x-shockwave-flash, application/vnd.ms-excel, > application/vnd.ms-powerpoint, application/msword, */* > Referer: http://www.some.com > Accept-Language: en-au > Content-Type: application/x-www-form-urlencoded > Accept-Encoding: gzip, deflate > User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) > Host: www.some.com > Content-Length: 62 > Connection: Keep-Alive > Cache-Control: no-cache > Cookie: SOME_CulturePref=en-AU; ASP.NET_SessionId=tl0iip55tn2gei55ofcg4145 > > userid=??????&pword=&pwordhid=14D2FC31E91171E0134FAA7E1C3F0039 > > > As you can see there is an additional cookie which is not being sent using > httpclient, it sends the ASP.NET one but not the CulturePref one. > > > > >From: Oleg Kalnichevski <[EMAIL PROTECTED]> > >Reply-To: "HttpClient Project" <[EMAIL PROTECTED]> > >To: [EMAIL PROTECTED] > >Subject: Re: Cookie Problem? > >Date: Mon, 13 Dec 2004 15:04:42 +0100 > > > >B K, > > > >> Date d = Calendar.getInstance().getTime(); > >> Cookie mycookie = new Cookie("www.some.com", "SOME_CulturePref", > >> "en-AU", > >> "/", d, false); > >> > >When you set the cookie's expiry like that you effectively render the > >cookie useless as it expires the same very moment it is created. > > > >I also feel this problem has nothing to do with the cookie's expiry > >attribute. Try using the browser compatibility cookie policy instead of > >RFC2109 one used per default and see if that makes any difference. > > > >Oleg > > > > > > > >On Sun, Dec 12, 2004 at 01:17:51AM +1100, B K wrote: > >> I have an issue with HTTPClient and a particular site which I can't get > >to > >> work with it, the basic problem is I get relocated to an error page > >instead > >> of the page I am expecting. I have used httpwatch to check out the > >cookies > >> and discovered there was an extra cookie which wasn't being set, so I > >then > >> manually set this cookie and I still get the same problem. I also try to > >> pass in a Date when creating the cookie(I thought this may be the > >problem) > >> but for some reason this causes a problem. Below is the log when I can > >> create the cookie but with no date. The code I use to create this cookie > >is > >> > >> Cookie mycookie = new Cookie("www.some.com", "SOME_CulturePref", > >"en-AU", > >> "/", null, false); > >> > >> 2004/12/12 00:56:48:890 EST [DEBUG] header - ->> "GET / > >HTTP/1.1[\r][\n]" > >> 2004/12/12 00:56:48:906 EST [DEBUG] header - ->> "User-Agent: Jakarta > >> Commons-HttpClient/3.0-beta1[\r][\n]" > >> 2004/12/12 00:56:48:906 EST [DEBUG] header - ->> "Host: > >> www.some.com[\r][\n]" > >> 2004/12/12 00:56:48:906 EST [DEBUG] header - ->> "[\r][\n]" > >> 2004/12/12 00:56:49:546 EST [DEBUG] header - -<< "HTTP/1.0 200 > >OK[\r][\n]" > >> 2004/12/12 00:56:49:546 EST [DEBUG] header - -<< "Date: Sat, 11 Dec 2004 > >> 13:56:45 GMT[\r][\n]" > >> 2004/12/12 00:56:49:562 EST [DEBUG] header - -<< "Server: > >> Microsoft-IIS/6.0[\r][\n]" > >> 2004/12/12 00:56:49:562 EST [DEBUG] header - -<< "X-Powered-By: > >> ASP.NET[\r][\n]" > >> 2004/12/12 00:56:49:562 EST [DEBUG] header - -<< "X-AspNet-Version: > >> 1.1.4322[\r][\n]" > >> 2004/12/12 00:56:49:562 EST [DEBUG] header - -<< "Set-Cookie: > >> ASP.NET_SessionId=yngm4yiquvheoobd12ppbjed; path=/[\r][\n]" > >> 2004/12/12 00:56:49:562 EST [DEBUG] header - -<< "Cache-Control: > >> private[\r][\n]" > >> 2004/12/12 00:56:49:562 EST [DEBUG] header - -<< "Content-Type: > >text/html; > >> charset=utf-8[\r][\n]" > >> 2004/12/12 00:56:49:562 EST [DEBUG] header - -<< "Content-Length: > >> 28976[\r][\n]" > >> 2004/12/12 00:56:49:562 EST [DEBUG] header - -<< "X-Cache: MISS from > >> DigiDefense.com[\r][\n]" > >> 2004/12/12 00:56:49:562 EST [DEBUG] header - -<< "Connection: > >close[\r][\n]" > >> > >> 2004/12/12 00:56:50:968 EST [DEBUG] header - ->> "POST /default.aspx > >> HTTP/1.1[\r][\n]" > >> 2004/12/12 00:56:50:968 EST [DEBUG] header - ->> "User-Agent: Jakarta > >> Commons-HttpClient/3.0-beta1[\r][\n]" > >> 2004/12/12 00:56:50:968 EST [DEBUG] header - ->> "Host: > >> www.some.com[\r][\n]" > >> 2004/12/12 00:56:50:968 EST [DEBUG] header - ->> "Cookie: $Version=0; > >> ASP.NET_SessionId=yngm4yiquvheoobd12ppbjed; $Path=/[\r][\n]" > >> 2004/12/12 00:56:50:968 EST [DEBUG] header - ->> "Cookie: $Version=0; > >> SOME_CulturePref=en-AU[\r][\n]" > >> 2004/12/12 00:56:50:968 EST [DEBUG] header - ->> "Content-Length: > >> 63[\r][\n]" > >> 2004/12/12 00:56:50:968 EST [DEBUG] header - ->> "Content-Type: > >> application/x-www-form-urlencoded[\r][\n]" > >> 2004/12/12 00:56:50:968 EST [DEBUG] header - ->> "[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "HTTP/1.0 302 Moved > >> Temporarily[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "Date: Sat, 11 Dec 2004 > >> 13:56:47 GMT[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "Server: > >> Microsoft-IIS/6.0[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "X-Powered-By: > >> ASP.NET[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "X-AspNet-Version: > >> 1.1.4322[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "Location: > >> /errorhandling/errorpage.aspx?ErrId=-500[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "Cache-Control: > >> private[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "Content-Type: > >text/html; > >> charset=utf-8[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "Content-Length: > >> 157[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "X-Cache: MISS from > >> DigiDefense.com[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [DEBUG] header - -<< "Connection: > >close[\r][\n]" > >> 2004/12/12 00:56:52:078 EST [INFO] HttpMethodDirector - -Redirect > >requested > >> but followRedirects is disabled > >> > >> I then create the cookie as follows with a date > >> > >> Date d = Calendar.getInstance().getTime(); > >> Cookie mycookie = new Cookie("www.some.com", "SOME_CulturePref", > >"en-AU", > >> "/", d, false); > >> > >> Below is the log for some reason the cookie doesn't get created > >> > >> 2004/12/12 01:05:16:921 EST [DEBUG] header - ->> "GET / > >HTTP/1.1[\r][\n]" > >> 2004/12/12 01:05:16:937 EST [DEBUG] header - ->> "User-Agent: Jakarta > >> Commons-HttpClient/3.0-beta1[\r][\n]" > >> 2004/12/12 01:05:16:937 EST [DEBUG] header - ->> "Host: > >> www.some.com[\r][\n]" > >> 2004/12/12 01:05:16:937 EST [DEBUG] header - ->> "[\r][\n]" > >> 2004/12/12 01:05:17:453 EST [DEBUG] header - -<< "HTTP/1.0 200 > >OK[\r][\n]" > >> 2004/12/12 01:05:17:453 EST [DEBUG] header - -<< "Date: Sat, 11 Dec 2004 > >> 14:05:13 GMT[\r][\n]" > >> 2004/12/12 01:05:17:453 EST [DEBUG] header - -<< "Server: > >> Microsoft-IIS/6.0[\r][\n]" > >> 2004/12/12 01:05:17:453 EST [DEBUG] header - -<< "X-Powered-By: > >> ASP.NET[\r][\n]" > >> 2004/12/12 01:05:17:453 EST [DEBUG] header - -<< "X-AspNet-Version: > >> 1.1.4322[\r][\n]" > >> 2004/12/12 01:05:17:453 EST [DEBUG] header - -<< "Set-Cookie: > >> ASP.NET_SessionId=pbgmhc55awpattzxznv3xind; path=/[\r][\n]" > >> 2004/12/12 01:05:17:453 EST [DEBUG] header - -<< "Cache-Control: > >> private[\r][\n]" > >> 2004/12/12 01:05:17:453 EST [DEBUG] header - -<< "Content-Type: > >text/html; > >> charset=utf-8[\r][\n]" > >> 2004/12/12 01:05:17:453 EST [DEBUG] header - -<< "Content-Length: > >> 28976[\r][\n]" > >> 2004/12/12 01:05:17:468 EST [DEBUG] header - -<< "X-Cache: MISS from > >> DigiDefense.com[\r][\n]" > >> 2004/12/12 01:05:17:468 EST [DEBUG] header - -<< "Connection: > >close[\r][\n]" > >> > >> 2004/12/12 01:05:18:828 EST [DEBUG] header - ->> "POST /default.aspx > >> HTTP/1.1[\r][\n]" > >> 2004/12/12 01:05:18:843 EST [DEBUG] header - ->> "User-Agent: Jakarta > >> Commons-HttpClient/3.0-beta1[\r][\n]" > >> 2004/12/12 01:05:18:843 EST [DEBUG] header - ->> "Host: > >> www.some.com[\r][\n]" > >> 2004/12/12 01:05:18:843 EST [DEBUG] header - ->> "Cookie: $Version=0; > >> ASP.NET_SessionId=pbgmhc55awpattzxznv3xind; $Path=/[\r][\n]" > >> 2004/12/12 01:05:18:843 EST [DEBUG] header - ->> "Content-Length: > >> 63[\r][\n]" > >> 2004/12/12 01:05:18:843 EST [DEBUG] header - ->> "Content-Type: > >> application/x-www-form-urlencoded[\r][\n]" > >> 2004/12/12 01:05:18:843 EST [DEBUG] header - ->> "[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "HTTP/1.0 302 Moved > >> Temporarily[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "Date: Sat, 11 Dec 2004 > >> 14:05:15 GMT[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "Server: > >> Microsoft-IIS/6.0[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "X-Powered-By: > >> ASP.NET[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "X-AspNet-Version: > >> 1.1.4322[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "Location: > >> /errorhandling/errorpage.aspx?ErrId=-500[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "Cache-Control: > >> private[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "Content-Type: > >text/html; > >> charset=utf-8[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "Content-Length: > >> 157[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "X-Cache: MISS from > >> DigiDefense.com[\r][\n]" > >> 2004/12/12 01:05:19:921 EST [DEBUG] header - -<< "Connection: > >close[\r][\n]" > >> 2004/12/12 01:05:19:937 EST [INFO] HttpMethodDirector - -Redirect > >requested > >> but followRedirects is disabled > >> Any help greatly appreciated haven't run into these sorts of problems > >> before with HttpClient. > >> > >> > >> > >> --------------------------------------------------------------------- > >> 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] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]