hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Best practise to add SOCKS proxy support?
Date Sat, 29 Aug 2009 09:45:50 GMT
Peter Paul wrote:
> On Tue, 25 Aug 2009 12:06:04 +0200
> Oleg Kalnichevski <olegk@apache.org> wrote:
> 
>> On Tue, Aug 25, 2009 at 01:25:21AM +0200, Peter Paul wrote:
>>
>> You should be using just a single instance of HttpClient, multiple
>> HostConfiguration objects (one per request), and (very important)
>> relative request URIs.
>>
>> Alternatively, you should consider upgrading to HttpClient 4.0 which
>> has a significantly better API.
>>
>> Hope this helps.
> 
> Thank you, but it's not my project, in fact, it's an OpenSource project
> and the application would only be usefull for me if it has SOCKS
> support, so I thought of adding it. I have not designed the underlying
> architecture, so I intended to change as few as possible about it.
> If I had found a way to easily support multiple SOCKS proxies in
> HttpClient 4.0, I would have put effort in porting the application to
> this, but I have neither found appropriate methods in the 4.0 api nor
> in the HostConfiguration object.
> Could you please clearify what you meant?
> 

(1) HttpClient 3.1

HttpClient client = new HttpClient();

ProtocolSocketFactory mysf = new DefaultProtocolSocketFactory();
Protocol myhttp = new Protocol("http", mysf, 80);
HostConfiguration hostconf = new HostConfiguration();
hostconf.setHost("targethost", 80, myhttp);
HttpState state = new HttpState();

GetMethod httpget = new GetMethod("/use/relative/uris/only");
try {
     client.executeMethod(hostconf, httpget, state);

     if (httpget.getStatusCode() == HttpStatus.SC_OK) {
         System.out.println(httpget.getResponseBodyAsString());
     } else {
       System.out.println("Unexpected failure: " + 
httpget.getStatusLine().toString());
     }
} finally {
     httpget.releaseConnection();
}

(2) HttpClient 4.0

Use custom ClientConnectionOperator

http://hc.apache.org/httpcomponents-client/tutorial/html/connmgmt.html#d4e552

Oleg




> Thank you
> 
> Peter
>  
>> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


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


Mime
View raw message