Hi,

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();
    proxyCredentials.setCredentials(
        new AuthScope(proxyUri.getHost(), proxyUri.getPort()),
        new UsernamePasswordCredentials("joe", "secret")
    );

    CredentialsProvider serviceCredentials = new BasicCredentialsProvider();
    serviceCredentials.setCredentials(
        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 =
RequestConfig.custom().setProxy(proxyHost).build();
    HttpGet httpGet = new HttpGet("/");
    httpGet.setConfig(config);
    System.out.println("executing request to " + targetHost + " via " +
proxyHost);

    CloseableHttpResponse response = httpclient.execute(targetHost,
httpGet);

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

Thanks!
Arul

Reply via email to