getting through a proxy server
Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getting through a proxy server
I believe that your problem is the fact that by calling the GetMethod(url) constructor, you are creating a method with its own host configuration; in this case, the method's host configuration is used when the method is executed (as opposed to the default host configuration that you have created on the connection). In other words, the host, port, and path information for the specific method invocation are extracted from the URL that you used to construct the GetMethod. If you replace this code: client.getHostConfiguration()... with this code: method.getHostConfiguration()... You should be all set. Either that or call the parameter-less GetMethod constructor, which will cause it to default to the host configuration for your client. OR you could call: client.executeMethod( client.getHostConfiguration(), method, client.getState()) That should work, too. Hope that helps, Bob -Original Message- From: Yuzwa, Erik [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 10:53 AM To: 'Commons HttpClient Project' Subject: RE: getting through a proxy server Madeleine, Stupid question but is your proxy server using NTLM authentication? I had to do some hoop jumping to get NTLM to work properly, but it's working now if you need some code. Erik -Original Message- From: Madeleine Wright [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 8:46 AM To: Commons HttpClient Project Subject: getting through a proxy server Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - 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]
Re: getting through a proxy server
Madeleine, If you activate wire/context logging in your application you'll get more details on what exactly goes wrong http://jakarta.apache.org/commons/httpclient/logging.html If you need help reading the log, feel free to post it to this list. Do obfuscate security sensitive bits such as logon credentials prior to posting. Oleg On Fri, 2004-10-08 at 16:45, Madeleine Wright wrote: Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] *** The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system. *** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getting through a proxy server
Bob, You are absolutely right about method.getHostConfiguration() taking precedence over client.getHostConfiguration(). However, HttpClient does copy the proxy information from the agent host config to the method host config. So, that should not be the reason for proxy problems Madeleine has been having. We realize this can be horribly confusing. As of release 3.0 the use of HttpMethod#getHostConfiguration() will be deprecated and discouraged Oleg On Fri, 2004-10-08 at 17:01, St Jacques, Robert wrote: I believe that your problem is the fact that by calling the GetMethod(url) constructor, you are creating a method with its own host configuration; in this case, the method's host configuration is used when the method is executed (as opposed to the default host configuration that you have created on the connection). In other words, the host, port, and path information for the specific method invocation are extracted from the URL that you used to construct the GetMethod. If you replace this code: client.getHostConfiguration()... with this code: method.getHostConfiguration()... You should be all set. Either that or call the parameter-less GetMethod constructor, which will cause it to default to the host configuration for your client. OR you could call: client.executeMethod( client.getHostConfiguration(), method, client.getState()) That should work, too. Hope that helps, Bob -Original Message- From: Yuzwa, Erik [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 10:53 AM To: 'Commons HttpClient Project' Subject: RE: getting through a proxy server Madeleine, Stupid question but is your proxy server using NTLM authentication? I had to do some hoop jumping to get NTLM to work properly, but it's working now if you need some code. Erik -Original Message- From: Madeleine Wright [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 8:46 AM To: Commons HttpClient Project Subject: getting through a proxy server Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - 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] *** The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system. *** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getting through a proxy server
Hi. Thanks for all the suggestions. I tried replacing client.getHostConfiguration()..with method.getHostConfiguration butit didn't seem to make any difference. I changed method back to client and retried and for the second attempt it did authenticate me - but not for the first. Initially I had this: retryhandler.setRetryCount(3); but then I changed the 3 to 1. Again the first try was refused but the second got through. What I would like to understand is which host configuration is being accessed by client.getHostConfiguration().., the proxy host, the ultimate destination or me?? I was using a logger - and I'm appending the output with the retry at 1 (not that it's any shorter!). Is there something in the order of the code that causes a refusal the first time around that gets fixed the second time? Currently my code (comments stripped out) looks like this: public class MyHttpClient { private static String url = http://www.uct.ac.za/;; public static void main(String[] args) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); client.getHostConfiguration().setProxy(, ); Credentials creds = new UsernamePasswordCredentials(, ); client.getState().setProxyCredentials(, cache.ru.ac.za, creds); Logger logger = Logger.getLogger(MyHttpClient.class); BasicConfigurator.configure(); logger.info(Entering application.); DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler(); retryhandler.setRequestSentRetryEnabled(false); retryhandler.setRetryCount(1); method.setMethodRetryHandler(retryhandler); try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println(Method failed: + method.getStatusLine()); } byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); } catch (IOException e) { System.err.println(Failed to download file.); e.printStackTrace(); } finally { method.releaseConnection(); } } } The error log follows. Thanks so much. Madeleine 468 [main] INFO MyHttpClient - Entering application. 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HttpMethod) 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState) 515 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.open() 547 [main] DEBUG org.apache.commons.httpclient.HttpConnection - HttpConnection.setSoTimeout(0) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.execute(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Execute loop try 1 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.processRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Attempt number 1 to process request 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.generateRequestLine(HttpConnection, String, String, String, String) 562 [main] DEBUG httpclient.wire.header - GET http://www.uct.ac.za/ HTTP/1.1[\r][\n] 562 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.print(String) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[]) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[], int, int) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Adding Host request header 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addCookieRequestHeader(HttpState, HttpConnection) 593 [main] DEBUG org.apache.commons.httpclient.HttpState - enter HttpState.getCookies() 593 [main] DEBUG org.apache.commons.httpclient.cookie.CookieSpec - enter CookieSpecBase.match(String, int, String, boolean, Cookie[]) 593 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addAuthorizationRequestHeader(HttpState,
Re: getting through a proxy server
Progress - just moved the GetMethod constructor down below the logging details. Now, though I still get a cache MISS at first, I don't get an authentication refusal. I also tried moving the credential details higher than the host configuration, but that didn't make any difference. Madeleine Oleg Kalnichevski wrote: Bob, You are absolutely right about method.getHostConfiguration() taking precedence over client.getHostConfiguration(). However, HttpClient does copy the proxy information from the agent host config to the method host config. So, that should not be the reason for proxy problems Madeleine has been having. We realize this can be horribly confusing. As of release 3.0 the use of HttpMethod#getHostConfiguration() will be deprecated and discouraged Oleg On Fri, 2004-10-08 at 17:01, St Jacques, Robert wrote: I believe that your problem is the fact that by calling the GetMethod(url) constructor, you are creating a method with its own host configuration; in this case, the method's host configuration is used when the method is executed (as opposed to the default host configuration that you have created on the connection). In other words, the host, port, and path information for the specific method invocation are extracted from the URL that you used to construct the GetMethod. If you replace this code: client.getHostConfiguration()... with this code: method.getHostConfiguration()... You should be all set. Either that or call the parameter-less GetMethod constructor, which will cause it to default to the host configuration for your client. OR you could call: client.executeMethod( client.getHostConfiguration(), method, client.getState()) That should work, too. Hope that helps, Bob -Original Message- From: Yuzwa, Erik [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 10:53 AM To: 'Commons HttpClient Project' Subject: RE: getting through a proxy server Madeleine, Stupid question but is your proxy server using NTLM authentication? I had to do some hoop jumping to get NTLM to work properly, but it's working now if you need some code. Erik -Original Message- From: Madeleine Wright [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 8:46 AM To: Commons HttpClient Project Subject: getting through a proxy server Please can someone suggest the simplest way to access a URL programatically through a proxy server? I'm using HttpClient and the proxy bits of my code look like this (everything else works fine - I can access all sites inside the firewall): HttpClient client = new HttpClient(); . client.getHostConfiguration().setProxy(proxyHost, proxyPort); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setProxyCredentials(realm, proxyHost, defaultcreds); ... GetMethod method = new GetMethod(url); I realize I seem to be supplying proxy host details twice! But I can't otherwise see how to set the proxy port? I keep getting an access denied message from the proxy server, indicating that I have not authenticated myself. Does anyone know how I do that other than the method above (I am sure the actual proxy details given are correct). Thanks. Mad - 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] *** The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system. *** - 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]
Re: getting through a proxy server
Hi Madeleine, The first request fails because the credentials are not sent on the first method execution. This is for two reasons. One, because the proxy credentials have been specified with a particular realm. HttpClient does not know that a URL is protected by a particular realm until is tries and fails. Also, HttpClient by default does not include credentials in requests except when challenged or when preemptive authentication has been turned on. You should be able to fix this problem by doing the following: // use a null realm client.getState().setProxyCredentials(null, cache.ru.ac.za, creds); // enable preemptive authentication client.getState().setAuthenticationPreemptive(true); Mike Madeleine Wright wrote: Hi. Thanks for all the suggestions. I tried replacing client.getHostConfiguration()..with method.getHostConfiguration butit didn't seem to make any difference. I changed method back to client and retried and for the second attempt it did authenticate me - but not for the first. Initially I had this: retryhandler.setRetryCount(3); but then I changed the 3 to 1. Again the first try was refused but the second got through. What I would like to understand is which host configuration is being accessed by client.getHostConfiguration().., the proxy host, the ultimate destination or me?? I was using a logger - and I'm appending the output with the retry at 1 (not that it's any shorter!). Is there something in the order of the code that causes a refusal the first time around that gets fixed the second time? Currently my code (comments stripped out) looks like this: public class MyHttpClient { private static String url = http://www.uct.ac.za/;; public static void main(String[] args) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); client.getHostConfiguration().setProxy(, ); Credentials creds = new UsernamePasswordCredentials(, ); client.getState().setProxyCredentials(, cache.ru.ac.za, creds); Logger logger = Logger.getLogger(MyHttpClient.class); BasicConfigurator.configure(); logger.info(Entering application.); DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler(); retryhandler.setRequestSentRetryEnabled(false); retryhandler.setRetryCount(1); method.setMethodRetryHandler(retryhandler); try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println(Method failed: + method.getStatusLine()); } byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); } catch (IOException e) { System.err.println(Failed to download file.); e.printStackTrace(); } finally { method.releaseConnection(); } } } The error log follows. Thanks so much. Madeleine 468 [main] INFO MyHttpClient - Entering application. 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HttpMethod) 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState) 515 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.open() 547 [main] DEBUG org.apache.commons.httpclient.HttpConnection - HttpConnection.setSoTimeout(0) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.execute(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Execute loop try 1 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.processRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Attempt number 1 to process request 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.generateRequestLine(HttpConnection, String, String, String, String) 562 [main] DEBUG httpclient.wire.header - GET http://www.uct.ac.za/ HTTP/1.1[\r][\n] 562 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.print(String) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[]) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[], int, int) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addUserAgentRequestHeaders(HttpState,
Re: getting through a proxy server
Also, preemptive authentication is covered in more detail at http://jakarta.apache.org/commons/httpclient/authentication.html. Mike Madeleine Wright wrote: Hi. Thanks for all the suggestions. I tried replacing client.getHostConfiguration()..with method.getHostConfiguration butit didn't seem to make any difference. I changed method back to client and retried and for the second attempt it did authenticate me - but not for the first. Initially I had this: retryhandler.setRetryCount(3); but then I changed the 3 to 1. Again the first try was refused but the second got through. What I would like to understand is which host configuration is being accessed by client.getHostConfiguration().., the proxy host, the ultimate destination or me?? I was using a logger - and I'm appending the output with the retry at 1 (not that it's any shorter!). Is there something in the order of the code that causes a refusal the first time around that gets fixed the second time? Currently my code (comments stripped out) looks like this: public class MyHttpClient { private static String url = http://www.uct.ac.za/;; public static void main(String[] args) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); client.getHostConfiguration().setProxy(, ); Credentials creds = new UsernamePasswordCredentials(, ); client.getState().setProxyCredentials(, cache.ru.ac.za, creds); Logger logger = Logger.getLogger(MyHttpClient.class); BasicConfigurator.configure(); logger.info(Entering application.); DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler(); retryhandler.setRequestSentRetryEnabled(false); retryhandler.setRetryCount(1); method.setMethodRetryHandler(retryhandler); try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println(Method failed: + method.getStatusLine()); } byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); } catch (IOException e) { System.err.println(Failed to download file.); e.printStackTrace(); } finally { method.releaseConnection(); } } } The error log follows. Thanks so much. Madeleine 468 [main] INFO MyHttpClient - Entering application. 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HttpMethod) 484 [main] DEBUG org.apache.commons.httpclient.HttpClient - enter HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState) 515 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.open() 547 [main] DEBUG org.apache.commons.httpclient.HttpConnection - HttpConnection.setSoTimeout(0) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.execute(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Execute loop try 1 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.processRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Attempt number 1 to process request 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequest(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection) 547 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.generateRequestLine(HttpConnection, String, String, String, String) 562 [main] DEBUG httpclient.wire.header - GET http://www.uct.ac.za/ HTTP/1.1[\r][\n] 562 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.print(String) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[]) 578 [main] DEBUG org.apache.commons.httpclient.HttpConnection - enter HttpConnection.write(byte[], int, int) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection) 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - Adding Host request header 578 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase - enter HttpMethodBase.addCookieRequestHeader(HttpState, HttpConnection) 593 [main] DEBUG org.apache.commons.httpclient.HttpState - enter HttpState.getCookies() 593 [main] DEBUG org.apache.commons.httpclient.cookie.CookieSpec - enter CookieSpecBase.match(String, int,
Re: getting through a proxy server
Hi, Mike. Thanks so much. That solved it! I originally had the ..setAuthenticationPreemptive(true)..bit but had taken it out because it didn't seem to work earlier. The explanations were really helpful too. This is an incredibly helpful list! Madeleine Michael Becke wrote: Hi Madeleine, The first request fails because the credentials are not sent on the first method execution. This is for two reasons. One, because the proxy credentials have been specified with a particular realm. HttpClient does not know that a URL is protected by a particular realm until is tries and fails. Also, HttpClient by default does not include credentials in requests except when challenged or when preemptive authentication has been turned on. You should be able to fix this problem by doing the following: // use a null realm client.getState().setProxyCredentials(null, cache.ru.ac.za, creds); // enable preemptive authentication client.getState().setAuthenticationPreemptive(true); Mike - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]