hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erxiang Liu <erxi...@us.ibm.com>
Subject Re: why https site returns 403 when using proxy server?
Date Wed, 03 Jan 2007 22:52:31 GMT

Hi, Roland:

Thanks a lot for the quick response!

No, I did not post the wrong code. But I forgot to explain that we actually
create a http URL handler which wrapped the apache http client code.
So when the applications do url.openConnection(), it is calling the apache
code, instead of the default JVM url Handler.

Yes, we did try to connect to the https site without the proxy server and
tried it using the browser.
both works. Yes. most likely it is the problem in my code as you suggested.
Also to note that connecting to a http site via proxy server works fine.

To make things less confusing, I use the apache code directly and tried
what Arun and Joshua suggested , here is the code:
public void testProxy() {
      String url = "https://bugs.eclipse.org/bugs/";
      GetMethod method = new GetMethod(url);
      try {
            HttpClient client = new HttpClient(
                              new MultiThreadedHttpConnectionManager());

            client.getHostConfiguration().setProxy("x.xx.xx.xxx", 80); //
"x.xx.xx.xxx" is the IP address of the proxy server
            AuthScope as = new AuthScope("x.xx.xx.xxx", 80);
                              as, new NTCredentials(proxyUser,
proxyPassword, InetAddress.getLocalHost().getHostName(), "xx.xx.xx"));
            //proxyUser is the user name to access the proxy server. and
proxyPassword is the password.
            int statusCode = client.executeMethod(method);
            System.out.println("response code = " + statusCode);
            byte[] responseBody = method.getResponseBody();

            System.out.println(new String(responseBody));

      } catch (HttpException e) {
                  System.err.println("Fatal protocol violation: " +
      } catch (IOException e) {
                  System.err.println("Fatal transport error: " +
      } finally {
                  // Release the connection.

Here is the output:
response code = 403
<title>403 Forbidden</title>
<p>You don't have permission to access bugs.eclipse.org:443
on this server.</p>
<hr />
<address>IBM_HTTP_Server/6.0 Apache/2.0.47 (Unix) Server at
bugs.eclipse.org Port 443</address>

I aslo tried to change
AuthScope as = new AuthScope("x.xx.xx.xxx", 80);
                        as, new NTCredentials(proxyUser, proxyPassword,
InetAddress.getLocalHost().getHostName(), "xx.xx.xx"));
client.getState().setProxyCredentials(AuthScope.ANY, new
But same output.

I thought  there is a very common user scenario and it should work. I
browsed some old apache messages. Some suggested to use
method.getHostConfiguration().setProxy("x.xx.xx.xxx", 80); some suggested
use client.getState().setAuthenticationPreemptive(true);
but none of them works.  Any idea why the acces is denied? Any suggestions?

thanks a lot!


             Roland Weber                                                  
             so.net>                                                    To 
                                       HttpClient User Discussion          
             01/02/2007 04:37          <httpclient-user@jakarta.apache.org 
             PM                        >                                   
             Please respond to                                     Subject 
             "HttpClient User          Re: why https site returns 403 when 
                Discussion"            using proxy server?                 

Hello Michelle,

> It works fine when I connect to a http site. eg.
> URL url = new URL("http://www.eclipse.org/");
> HttpURLConnection conn = (HttpURLConnection)url.openConnection();
> int result = conn.getResponseCode();
> the response code I got is 200.

I assume that you are aware that URL.openConnection() will
*not* use HttpClient and that you just pasted the wrong
example code into your mail.

1. Have you tried connecting to the HTTPS URL directly,
   without the proxy inbetween? See our SSL guide:

2. Have you tried connecting to the HTTPS URL through
   the proxy but with a standard web browser?

If both of these work, and only the combination of
HttpClient through proxy to the HTTPS URL fails, then
you most likely have some problem in your code.
In that case, a more detailed description of what
fails would be helpful. And/or a wire log:
A wire log of the headers should be sufficient.

hope that helps,

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

  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message