You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Remis (JIRA)" <ji...@apache.org> on 2013/11/21 15:03:36 UTC

[jira] [Created] (HTTPCLIENT-1435) Proxy authentication of Fluent API does not work

Remis created HTTPCLIENT-1435:
---------------------------------

             Summary: Proxy authentication of Fluent API does not work
                 Key: HTTPCLIENT-1435
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1435
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: Fluent HC
    Affects Versions: 4.3.1
         Environment: Win7 + JDK6 + HttpClient 4.3.1 + HttpCore 4.3
            Reporter: Remis


The sample code below demonstrates the issue.
{code:title=Test.java}
package com.test;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;

public class Test {
    public static void main(final String[] args) {
        final HttpHost proxy = new HttpHost("my-proxy.com", 8080);
        final String username = "username";
        final String password = "password";
        final String uri = "https://www.my-uri.com/servlet/action";

        // WORKS: HTTP/1.1 200 OK
        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(username, password));
        final HttpPost httppost = new HttpPost(uri);
        httppost.setConfig(RequestConfig.custom().setProxy(proxy).build());
        try {
            System.out.println(HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build()
                    .execute(httppost).getStatusLine());
        } catch (final Exception e) {
            e.printStackTrace();
        }

        // WORKS: as expected: HTTP/1.1 407 Proxy Authentication Required
        try {
            System.out.println(Request.Post(uri).viaProxy(proxy).execute().returnResponse().getStatusLine());
        } catch (final Exception e) {
            e.printStackTrace();
        }

        // FAILS (not expected): java.net.UnknownHostException:
        try {
            final Executor executor = Executor.newInstance().auth(proxy, username, password).authPreemptive(proxy);
            System.out.println(executor.execute(Request.Post(uri).viaProxy(proxy)).returnResponse().getStatusLine());
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
}
{code}



--
This message was sent by Atlassian JIRA
(v6.1#6144)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org