On Sat, 2008-06-07 at 23:23 +0200, Quintin Beukes wrote:
> Hey All,
>
> Good news. After a lot of debug stepping and trial/error I think I
> finally figured out how to do this.
>
> You create the HttpHost object you wish to send as the host request header.
> Then you do the following (where request is your request object and
> requestHost is the HttpHost you setup for the header).
>
> request = new BasicHttpRequest(method, url.toExternalForm(),
> HttpVersion.HTTP_1_1);
> request.getParams().setParameter(ClientPNames.VIRTUAL_HOST, requestHost);
>
> So far this seems to be the most correct way. If anyone knows a better
> or more correct way, please let me know.
>
Quintin,
This is indeed the correct way. The API will feel much less awkward if
you use relative request URIs instead of the absolute ones.
HttpParams params = new BasicHttpParams();
DefaultHttpClient httpclient = new DefaultHttpClient(params);
HttpHost targetHost = new HttpHost("www.google.com");
HttpGet httpget = new HttpGet("/");
httpget.getParams().setParameter(ClientPNames.VIRTUAL_HOST,
new HttpHost("www.google.ru"));
HttpResponse response = httpclient.execute(targetHost, httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
entity.consumeContent();
}
Alternatively if you can provide a custom protocol interceptor to set
the 'Host' request header any way you deem fit for your application.
Hope this helps
Oleg
> Quintin
>
> On Sat, Jun 7, 2008 at 10:32 PM, Quintin Beukes <[EMAIL PROTECTED]> wrote:
> > Hey,
> >
> > I found a possible solution to my problem, but I don't know how to approach
> > it.
> >
> > One way to do it is to set the Host header. Then it does the
> > connection to whatever HttpHost object I set up, and sends the host
> > header I define.
> >
> > But this doesn't feel right. I would ideally want it to connect to
> > server X, but use the header specified in the URL. I noticed in the
> > source that it uses an HttpRoute object to specify where it connects
> > to (I might have misread/misinterpreted it). Eitherway, is there a
> > more correct, or better way to do this?
> >
> > I was thinking something along the lines of:
> > 1. Use HttpHost to specify the host header
> > 2. Specify a route to use via some other technique
> > 3. Then it connects to the route in (2.) and sends the request line,
> > ex. "GET /path/to HTTP/1.1", and then the host specified in (1.) like
> > "Host: myhost.com:8581"
> >
> > OR something like this:
> > 1. Connect to the host/port specified in HttpHost
> > 2. Then HttpClient uses the host specified in the URI string (if any)
> > to create the Host header.
> >
> > --
> > Quintin Beukes
> >
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]