On Sun, 2008-05-25 at 10:26 +0200, Simon Green wrote:
> Hi,
> I would like to get the following code snippet to work using the HttpClient
> 4.0 alpha-4 release:
>
> ===========
> 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);
Simon,
You can set the default proxy on the client level
httpclient.getParams().setParameter
(ConnRoutePNames.DEFAULT_PROXY, proxy);
http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java
or on the individual request level.
Alternatively if you want a complete control over the request routing
you can provide a custom HttpRoutePlanner implementation
http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/routing/HttpRoutePlanner.java
Hope this helps
Oleg
> 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("----------------------------------------");
> ===========
>
> Unfortunately,it appears the RoutedRequest.Impl class has disappeared from
> the API since Alpha-3. Any ideas of how I can do this with the current
> release?
>
> Cheers,
>
> Simon.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]