Oleg Kalnichevski wrote:
Stuart White wrote:
This question is in response to the following post:

http://marc.info/?l=httpclient-users&m=121147890106497&w=2

This message describes the appropriate way to determine where an http
request was redirected.

It seems that this code does not function properly when going through a proxy.

I've attached example code.

To demonstrate, run the example.  You see that "http://www.google.com";
correctly gets redirected to "http://www.google.com/"; (notice the
trailing slash).

Now, edit redirect.java.  Change line 28 to "if (true)" and change
line 30 to use your proxy host.  Then re-run the example.

When I do this, I get the following output:

ResolvedURL=http://www.google.comhttp://www.google.com

Any ideas why this is happening?  Do I need different logic to
determine the redirect url when going through a proxy?

Thanks!
Stuart

Hi Stuart

It is obviously a bug in HttpClient. However, I do not think this has anything to do with redirect handling. Most likely things get screwy much earlier, when calculating the request URI for the proxied request.

I will look into fixing the problem.

Cheers

Oleg


Hi Stuart,

You know what? I am unable to reproduce the problem using the latest SVN snapshot. URLs without a trailing slash seem to be handled correctly.

----------
[DEBUG] headers - >> GET http://www.google.com HTTP/1.1
[DEBUG] headers - >> Host: www.google.com
[DEBUG] headers - >> Connection: Keep-Alive
[DEBUG] headers - >> User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.5)
[DEBUG] headers - << HTTP/1.1 302 Found
[DEBUG] headers - << Location: http://www.google.ch/
[DEBUG] headers - << Cache-Control: private
[DEBUG] headers - << Content-Type: text/html; charset=UTF-8
[DEBUG] headers - << Set-Cookie: PREF=ID=bb882c7ed444c8c7:TM=1228512916:LM=1228512916:S=cTMv6jcJVtGitDmb; expires=Sun, 05-Dec-2010 21:35:16 GMT; path=/; domain=.google.com
[DEBUG] headers - << Date: Fri, 05 Dec 2008 21:35:16 GMT
[DEBUG] headers - << Server: gws
[DEBUG] headers - << Content-Length: 218
[DEBUG] headers - >> GET http://www.google.ch/ HTTP/1.1
[DEBUG] headers - >> Host: www.google.ch
[DEBUG] headers - >> Connection: Keep-Alive
[DEBUG] headers - >> User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.5)
[DEBUG] headers - << HTTP/1.1 200 OK
[DEBUG] headers - << Cache-Control: private, max-age=0
[DEBUG] headers - << Date: Fri, 05 Dec 2008 21:35:18 GMT
[DEBUG] headers - << Expires: -1
[DEBUG] headers - << Content-Type: text/html; charset=ISO-8859-1
[DEBUG] headers - << Set-Cookie: PREF=ID=eceef32d105f622d:TM=1228512918:LM=1228512918:S=mF2kcMw8NhyuQEr8; expires=Sun, 05-Dec-2010 21:35:18 GMT; path=/; domain=.google.ch
[DEBUG] headers - << Server: gws
[DEBUG] headers - << Content-Length: 6367
----------

Could you please get the latest code snapshot and re-test your application?

Here's the test code I used:

----------
DefaultHttpClient httpclient = new DefaultHttpClient();

HttpHost proxy = new HttpHost("localhost", 8080);

httpclient.getParams().setParameter
    (ConnRoutePNames.DEFAULT_PROXY, proxy);

HttpContext localContext = new BasicHttpContext();
HttpGet httpget = new HttpGet("http://www.google.com";);

HttpResponse response = httpclient.execute(httpget, localContext);
HttpEntity entity = response.getEntity();

System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
if (entity != null) {
    entity.consumeContent();
}

-----------

Oleg




------------------------------------------------------------------------

---------------------------------------------------------------------
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]

Reply via email to