You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Kalnichevski, Oleg" <ol...@bearingpoint.com> on 2003/01/24 19:11:07 UTC

[PATCH] Custom HTTP connection example by Armando Anton


-----Original Message-----
From: Armando Anton [mailto:armando.anton@newknow.com]
Sent: Freitag, 24. Januar 2003 17:58
To: Commons HttpClient Project
Subject: RE: SSL & proxy question


Thank you for helping :)

i finally can connect to a secure web using the proxy and the HttpConnection class instead of the HttpClient :)

i will post here my example code (perhaps it helps to someome more)

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod;

public class TestSSLAndProxy {

    public static void main(String[] args) throws Exception {

        HttpState state = new HttpState();
        String _uri = "https://www.pairnic.com:443/main.m";
         URI uri = new URI(_uri.toCharArray()); // i like this constructor :)
        boolean isSecure = uri.getScheme() != null &&
                uri.getScheme().equals("https");
        HttpMethod method = new GetMethod( uri.toString() );
        ConnectMethod connectMethod = null;
        String host = uri.getHost();
        int port = uri.getPort();
        HttpConnection connection = new HttpConnection( host, port, isSecure );
        connection.setProxyHost("proxy.xxx.com");
        connection.setProxyPort(80);
        int status = 0;
        if (connection.isProxied() && connection.isSecure()) {
            connectMethod = new ConnectMethod(method);
            status = connectMethod.execute(state, connection);
        } else {
            status = method.execute(state, connection);
        }

        System.out.println("Status: " + status);
        System.out.println(method.getResponseBodyAsString());
    }
}

Armando

-----Original Message-----
From: Armando Anton 
Sent: viernes, 24 de enero de 2003 17:19
To: Commons HttpClient Project
Subject: RE: SSL & proxy question


Hi SSL friends :)

I know that the proxy accepts a CONNECT method when requesting secure pages.

But i uses directly an HttpConnection configured with a proxy when accesing to non-secure pages and it works perfect, but when accesing to secure pages i have the problem i have reported

Now i have the doubt if i must change how i use and manage the HttpConnection when accesing to secure pages or the HttpConnection (or HttpMethodBase) should be smarter and do it transparently.

Thanks,

Armando



-----Original Message-----
From: Ortwin Glück [mailto:ortwin.glueck@nose.ch]
Sent: viernes, 24 de enero de 2003 17:06
To: Commons HttpClient Project
Subject: Re: SSL & proxy question


You were basically trying to send a GET directly to the Proxy. But the 
proxy accepts a CONNECT method only.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>