hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "nitya vyas" <nitya.v...@gmail.com>
Subject Re: How to set proxy information in httpClient object from browser
Date Wed, 12 Sep 2007 11:55:57 GMT
I get the proxy settings with following code..... userful one...

          System.setProperty("java.net.useSystemProxies","true");
          List l = ProxySelector.getDefault().select(new URI("
https://www.yahoo.com"));
                for (Iterator iter = l.iterator(); iter.hasNext(); ){
                    Proxy proxy1 = (Proxy) iter.next();
                    System.out.println("proxy type : " + proxy1.type());
                    InetSocketAddress addr = (InetSocketAddress)
proxy1.address();
                    if(addr == null){
                        System.out.println("No Proxy");
                    }else{
                        String proxyHost = addr.getHostName();
                        int proxyPort = addr.getPort();
                        System.out.println("proxy hostname : " +
addr.getHostName());
                        System.out.println("proxy port : " + addr.getPort
());
                    }
                }

When i run this code i get the proxy settings of the IE.. eventhough my
default browser is Firefox i got the settings from IE. i checked the same by
removing from IE and didnt get anything in that case..

Now when i use the same httpClient object with setting proxy... and try to
execute the method... httpClient.executeMethod(xyz) it just stops there..
and then after a long wait it gives java.net.SocketException: Connection
reset ......

i dont know wat is wrong.. can anyone throw some light on this?????

thanks

On 9/6/07, Puneet Lakhina <puneet.lakhina@gmail.com> wrote:
>
> On 8/29/07, nitya vyas <nitya.vyas@gmail.com> wrote:
> >
> > Hi there,
> > I am using a single HTTPClient object (static) for the desktop
> application
> > with different method objects (get,post,multipartpost) for each call..I
> > have also implemented StrictSSLSocketFactory implementation (SSL) for
> that
> > httpClient object. Now i m suppose to get the proxy information from the
> > default browser and set the proxy for all requests. I believe it must be
> > done for the same static httpClient object for my app but dont know
> how..
>
>
> Two things
> 1. How to get the default proxy settings from the system. IDid some
> googling
> on this, found no way to easily get the windows default internet settings
> (similar to what firefox can do on windows when you install and run it).
>
> 2. How to set a proxy - I have done this for absolute basic httpclient,
> dont
> know if anything different needs to be done for SSL connections. For this
> you can use the HostConfiguration parameter of the executeMethod method.
> Something like this
> HttpClient httpClient = new HttpClient();
> GetMethod getMethod = new GetMethod("http://www.apache.org/");
> HostConfiguration hostConfig = new HostConfiguration();
> //set proxy host and port
> hostConfig.setProxy("my.proxy.address",80);
>
> client.executeMethod(getMethod,hostConfig);
> //Dont forget
> method.releaseConnection();
>
>
> can anyone please guide me how this can be achieved? I think setProxy()
> can
> > be done on HttpConnection object and not HTTPClient. So how do i set the
> > proxy for my httpClient ???
> >
> > thanks.
> > Nitya
> >
>
> Hope it helps.
>
> --
> Puneet
>

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