hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arul Dhesiaseelan <ar...@acm.org>
Subject Proxy authentication + Basic authentication on the Client instance
Date Mon, 23 Dec 2013 06:55:52 GMT

I am using a proxy to connect to a web service. Both proxy and web service
are secured with different set of credentials. I am trying to perform a GET
request using Apache HttpClient 4.3.1.

    URI proxyUri = URI.create("http://localhost:9000");
    URI targetUri = URI.create("http://localhost:8080");
    final HttpHost proxyHost = new HttpHost(proxyUri.getHost(),
proxyUri.getPort(), proxyUri.getScheme());
    final HttpHost targetHost = new HttpHost(targetUri.getHost(),
targetUri.getPort(), targetUri.getScheme());
    CredentialsProvider proxyCredentials = new BasicCredentialsProvider();
        new AuthScope(proxyUri.getHost(), proxyUri.getPort()),
        new UsernamePasswordCredentials("joe", "secret")

    CredentialsProvider serviceCredentials = new BasicCredentialsProvider();
        new AuthScope(targetHost.getHostName(), targetHost.getPort()),
        new UsernamePasswordCredentials("user", "password"));

    CloseableHttpClient httpclient = HttpClients.custom()
        .setDefaultCredentialsProvider(serviceCredentials).build();// this
sets only service creds

It looks like you can set only one set of credentials at any time. I could
not set both on the client. I tried something like this, but it would not
allow me to set proxy credentials on the request config.

    RequestConfig config =
    HttpGet httpGet = new HttpGet("/");
    System.out.println("executing request to " + targetHost + " via " +

    CloseableHttpResponse response = httpclient.execute(targetHost,

How can I use both of these credentials on the client? Is this supported?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message