On Wed, 2007-12-12 at 08:44 -0800, peridian wrote:
> Maybe I'm being stupid, but I need help with HttpPost.
> 
> I can do an HttpRequest through a Proxy HttpHost, but I can't seem to figure
> out how to send a Post message through a Proxy.
> 
> I thought there would be a RoutedPost or something.  Can I use the
> RoutedRequest to send an HttpPost?  (seems unlikely to my mind).
> 
> Any help is appreciated.
> 

You are using HttpClient 4.0-alpha2 I assume?

Try this:

===========
DefaultHttpClient  httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
        new AuthScope("localhost", 8080), 
        new UsernamePasswordCredentials("user", "pw"));

HttpHost targetHost = new HttpHost("www.google.co.uk", 80); 
HttpHost proxy = new HttpHost("localhost", 8080); 
HttpRoute route = new HttpRoute(targetHost, null, proxy, false);

HttpGet httpget = new HttpGet("http://www.google.co.uk/";);

RoutedRequest routedReq = new RoutedRequest.Impl(httpget, route); 
System.out.println("executing request to " + route);

HttpResponse response = httpclient.execute(routedReq, null);
HttpEntity entity = response.getEntity();

System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
    System.out.println("Response content length: " +
entity.getContentLength());
    System.out.println("Chunked?: " + entity.isChunked());
}
if (entity != null) {
    entity.consumeContent();
}

System.out.println("----------------------------------------");

===========

Hope this helps

Oleg

> Regards,
> Rob.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to