You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by peridian <ma...@robertstraughan.co.uk> on 2007/12/12 17:44:49 UTC
HttpPost through a Proxy
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.
Regards,
Rob.
--
View this message in context: http://www.nabble.com/HttpPost-through-a-Proxy-tp14298759p14298759.html
Sent from the HttpComponents-Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
Re: HttpPost through a Proxy
Posted by Roland Weber <os...@dubioso.net>.
Hello Rob,
> 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.
What kind of request can you do? HttpGet? HttpHead? HttpPost?
They're all requests, no matter what the method. And they're
all treated the same with respect to routing.
> I thought there would be a RoutedPost or something. Can I use the
> RoutedRequest to send an HttpPost?
Yes, just use the HttpPost as the request.
cheers,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org
Re: HttpPost through a Proxy
Posted by Oleg Kalnichevski <ol...@apache.org>.
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: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org