------Mensaje original------
De: visualize
Para:httpclient-users@hc.apache.org
Responder a:HttpClient User Discussion
Asunto: Re: HttpClient 4.0
Enviado: 28 Sep, 2009 11:06



olegk wrote:
> 
> visualize wrote:
>> Hello,
>> 
>> I'm trying to port my application to use HttpClient 4.0 instead of
>> version
>> 3.0 I make a substantial number of HTTP-gets and used to use
>> aMultiThreadedHttpConnectionManager to setup a pool and retrieve clients. 
>> 
>> Let's say I want to get some stuff from
>> "http://my.server.com:8080/my-rest-service/data"; and
>> "http://my.server.com:8080/my-rest-service/data2";.
>> 
>> In 3.0 you are able to set host and port via
>> getHostConfiguration().setHost(host, port) which was kind of 
>> convenient since I then could just create the pool, and when getting
>> clients
>> just set the host and port to "http://my.server.com"; and 8080. In each
>> request, I just had to set the URL to "/my-rest-service/data" or
>> "/my-rest-service/data2" and didn't have to care about the host and port.
>> 
>> Is there a way to accomplish the same with a client of version 4.0? Like
>> set
>> a default host/route (or whatever you may call it), so when doing new
>> HttpGet("/my-rest-service/data") it "falls back" to the default one?
>> 
>> / K
>> 
>> 
> 
> 
> Use "http.default-host" parameter.
> 
> -----
> DefaultHttpClient httpclient = new DefaultHttpClient();
> 
> httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST,
>          new HttpHost("www.google.com", 80, "http"));
> 
> HttpGet req = new HttpGet("/");
> 
> HttpResponse rsp = httpclient.execute(req);
> HttpEntity entity = rsp.getEntity();
> 
> System.out.println("----------------------------------------");
> System.out.println(rsp.getStatusLine());
> System.out.println("----------------------------------------");
> 
> if (entity != null) {
>      System.out.println(EntityUtils.toString(entity));
> }
> -----
> 
> Hope this helps
> 
> Oleg
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
> 
> 
> 

Fantastic, thanks a lot!
-- 
View this message in context: 
http://www.nabble.com/HttpClient-4.0-tp25531034p25641698.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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



Enviado desde mi dispositivo BlackBerry® de Orange.

Reply via email to