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.getHttpConnectionManager().getParams().setConnectionTimeout(
                              30000);
            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);
            client.getState().setProxyCredentials(
                              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: " +
e.getMessage());
                  e.printStackTrace();
      } catch (IOException e) {
                  System.err.println("Fatal transport error: " +
e.getMessage());
                  e.printStackTrace();
      } finally {
                  // Release the connection.
                  method.releaseConnection();
      }
}


Here is the output:
response code = 403
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<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>
</body></html>

I aslo tried to change
AuthScope as = new AuthScope("x.xx.xx.xxx", 80);
client.getState().setProxyCredentials(
                        as, new NTCredentials(proxyUser, proxyPassword,
InetAddress.getLocalHost().getHostName(), "xx.xx.xx"));
to
client.getState().setProxyCredentials(AuthScope.ANY, new
UsernamePasswordCredentials(
                        proxyUser,proxyPassword));
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!

Michelle



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




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:
http://jakarta.apache.org/commons/httpclient/sslguide.html

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:
http://jakarta.apache.org/commons/httpclient/logging.html
A wire log of the headers should be sufficient.

hope that helps,
  Roland

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


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