Return-Path: Delivered-To: apmail-jakarta-httpclient-user-archive@www.apache.org Received: (qmail 44976 invoked from network); 12 Jul 2006 10:19:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Jul 2006 10:19:18 -0000 Received: (qmail 77529 invoked by uid 500); 12 Jul 2006 10:19:16 -0000 Delivered-To: apmail-jakarta-httpclient-user-archive@jakarta.apache.org Received: (qmail 77440 invoked by uid 500); 12 Jul 2006 10:19:16 -0000 Mailing-List: contact httpclient-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: "HttpClient User Discussion" Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-user@jakarta.apache.org Received: (qmail 77423 invoked by uid 99); 12 Jul 2006 10:19:16 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Jul 2006 03:19:16 -0700 X-ASF-Spam-Status: No, hits=0.8 required=10.0 tests=INFO_TLD X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [85.90.206.104] (HELO office.redwerk.com) (85.90.206.104) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Jul 2006 03:19:14 -0700 Received: from bofh by office.redwerk.com with local (Exim 4.62 (FreeBSD)) (envelope-from ) id 1G0bnx-0002Cb-MN for httpclient-user@jakarta.apache.org; Wed, 12 Jul 2006 13:18:53 +0300 Date: Wed, 12 Jul 2006 13:18:53 +0300 From: Eugeny N Dzhurinsky To: httpclient-user@jakarta.apache.org Subject: wrong cookies passed back to httpclient? Message-ID: <20060712101853.GA8418@office.redwerk.com> Mail-Followup-To: httpclient-user@jakarta.apache.org Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline User-Agent: Mutt/1.5.11 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hello again! I still fighting with weird situation while same page is displayed well using browser, but with HttpClient error 500 is returned. Here is my unit test below: import java.io.IOException; import junit.framework.Assert; import junit.framework.TestCase; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpVersion; import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Level; import org.apache.log4j.Logger; public class HTTPClientTest extends TestCase { private static Logger log = Logger.getLogger(HTTPClientTest.class); HttpClient client; GetMethod get; String url; protected void setUp() throws Exception { client = new HttpClient(); url = "http://atlanta.familypages.info/out-35.html"; BasicConfigurator.configure(); log.setLevel(Level.DEBUG); } public void testResultcode() { try { URI uri = getURI(url); get = new GetMethod(); get.setURI(uri); setMethodParameters(); client.executeMethod(get); get = handleRedirects(20); Assert.assertEquals(HttpStatus.SC_OK, get.getStatusCode()); } catch (HttpException e) { e.printStackTrace(System.out); } catch (IOException e) { e.printStackTrace(System.out); } } private GetMethod handleRedirects(int redirects) throws URIException, IOException { switch (get.getStatusCode()) { case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_MOVED_TEMPORARILY: case HttpStatus.SC_SEE_OTHER: case HttpStatus.SC_TEMPORARY_REDIRECT: Header[] headers = get.getResponseHeaders("location"); if (headers != null && headers.length > 0) { String location = customEscape(headers[headers.length - 1] .getValue()); if (location.indexOf("://") == -1) { URI uri = new URI(get.getURI(), location, location .indexOf("%") > -1); location = uri.getURI(); } if (log.isDebugEnabled()) log.debug("Handling redirect for " + location + " level " + redirects); get.releaseConnection(); get = new GetMethod(); get.setURI(getURI(location)); setMethodParameters(); client.executeMethod(get); if (redirects > 0) handleRedirects(redirects - 1); } } return get; } private void setMethodParameters() { get.setFollowRedirects(false); HttpMethodParams p = get.getParams(); p.setVersion(new HttpVersion(1, 1)); p.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); } private URI getURI(String _url) throws URIException { _url = customEscape(_url); return new URI(_url, _url.indexOf('%') != -1); } private String customEscape(String _url) { String _internal_url = _url.indexOf(" ") > -1 && _url.indexOf("%") > -1 ? _url .replaceAll(" ", "%20") : _url; return _internal_url; } } for HttpClient headers are: GET /madeline/default.asp?GCID=C1000x047&AID=10280172&PID=1453275 HTTP/1.1 User-Agent: Jakarta Commons-HttpClient/3.0.1 Host: www.allaboardtoys.com HTTP/1.1 302 Object moved Server: Microsoft-IIS/5.0 Date: Wed, 12 Jul 2006 09:57:38 GMT P3P: policyref="http://www.allaboardtoys.com/w3c/p3p.xml" X-Powered-By: ASP.NET Pragma: no-cache cache-control: no-store Cache-Control: no-cache, must-revalidate Location: http://www.allaboardtoys.com/madeline/?GCID=C1000x047&AID=10280172&PID=1453275 Location: /madeline Content-Length: 130 Content-Type: text/html Expires: Tue, 11 Jul 2006 09:57:38 GMT Set-Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=A4AD8C16350E42B500ECC55B4F45FE8C; expires=Thu, 27-Jul-2006 09:57:38 GMT; domain=allaboardtoys.com; path=/ Set-Cookie: ASPSESSIONIDCSRAQQTS=GFIGGBPBPBAKFJMDODCENAKH; path=/ Cache-control: no-cache ---------------------------------------------------------- GET /madeline HTTP/1.1 User-Agent: Jakarta Commons-HttpClient/3.0.1 Host: www.allaboardtoys.com Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=A4AD8C16350E42B500ECC55B4F45FE8C Cookie: ASPSESSIONIDCSRAQQTS=GFIGGBPBPBAKFJMDODCENAKH HTTP/1.1 302 Object Moved Location: http://www.allaboardtoys.com/madeline/ Server: Microsoft-IIS/5.0 Content-Type: text/html Content-Length: 161 ---------------------------------------------------------- GET /madeline/ HTTP/1.1 User-Agent: Jakarta Commons-HttpClient/3.0.1 Host: www.allaboardtoys.com Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=A4AD8C16350E42B500ECC55B4F45FE8C Cookie: ASPSESSIONIDCSRAQQTS=GFIGGBPBPBAKFJMDODCENAKH HTTP/1.1 500 Internal Server Error Server: Microsoft-IIS/5.0 Date: Wed, 12 Jul 2006 09:57:38 GMT P3P: policyref="http://www.allaboardtoys.com/w3c/p3p.xml" X-Powered-By: ASP.NET Pragma: no-cache cache-control: no-store Cache-Control: no-cache, must-revalidate Content-Length: 318 Content-Type: text/html Expires: Tue, 11 Jul 2006 09:57:38 GMT Set-Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=A4AD8C16350E42B500ECC55B4F45FE8C%2CASPSESSIONIDCSRAQQTS%3DGFIGGBPBPBAKFJMDODCENAKH; expires=Thu, 27-Jul-2006 09:57:38 GMT; domain=allaboardtoys.com; path=/ Cache-control: no-cache and for firefox: GET /madeline/default.asp?GCID=C1000x047&AID=10280172&PID=1453275 HTTP/1.1 Host: www.allaboardtoys.com User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.0.4) Gecko/20060614 Firefox/1.5.0.4 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: ru,en;q=0.7,en-us;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: KOI8-R,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=00B7DB4FE1034AF289DAA46000102466 HTTP/1.x 302 Object moved Server: Microsoft-IIS/5.0 Date: Wed, 12 Jul 2006 10:05:18 GMT X-Powered-By: ASP.NET P3P: policyref="http://www.allaboardtoys.com/w3c/p3p.xml" Pragma: no-cache Cache-Control: no-store, no-cache, must-revalidate, no-cache Location: /madeline Content-Length: 130 Content-Type: text/html Expires: Tue, 11 Jul 2006 10:05:18 GMT Set-Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=00B7DB4FE1034AF289DAA46000102466; expires=Thu, 27-Jul-2006 10:05:18 GMT; domain=allaboardtoys.com; path=/ Set-Cookie: ASPSESSIONIDCATQCDDQ=COIDDADBJEONBCNBBAKPGIBM; path=/ ---------------------------------------------------------- GET /madeline HTTP/1.1 Host: www.allaboardtoys.com User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.0.4) Gecko/20060614 Firefox/1.5.0.4 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: ru,en;q=0.7,en-us;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: KOI8-R,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=00B7DB4FE1034AF289DAA46000102466; ASPSESSIONIDCATQCDDQ=COIDDADBJEONBCNBBAKPGIBM HTTP/1.x 302 Object Moved Location: http://www.allaboardtoys.com/madeline/ Server: Microsoft-IIS/5.0 Content-Type: text/html Content-Length: 161 ---------------------------------------------------------- GET /madeline/ HTTP/1.1 Host: www.allaboardtoys.com User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.0.4) Gecko/20060614 Firefox/1.5.0.4 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: ru,en;q=0.7,en-us;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: KOI8-R,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=00B7DB4FE1034AF289DAA46000102466; ASPSESSIONIDCATQCDDQ=COIDDADBJEONBCNBBAKPGIBM HTTP/1.x 200 OK Server: Microsoft-IIS/5.0 Date: Wed, 12 Jul 2006 10:05:18 GMT X-Powered-By: ASP.NET P3P: policyref="http://www.allaboardtoys.com/w3c/p3p.xml" Pragma: no-cache Cache-Control: no-store, no-cache, must-revalidate, no-cache Content-Length: 23672 Content-Type: text/html Expires: Tue, 11 Jul 2006 10:05:18 GMT Set-Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=00B7DB4FE1034AF289DAA46000102466; expires=Thu, 27-Jul-2006 10:05:18 GMT; domain=allaboardtoys.com; path=/ Is there anything I can try with HttpClient to avoid this error? -- Eugene N Dzhurinsky --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: httpclient-user-help@jakarta.apache.org