使用Microsoft TMG代理+ HTTP Post + SSL的ApacheHttpClient 4.3.3问题

时间:2015-01-16 22:56:32

标签: apache proxy apache-httpclient-4.x

我在通过Microsoft TMG和httpclient 4.3.3向Salesforce的web2lead servlet发送POST请求时遇到问题。如果我使用Ctnlm作为代理尝试请求,它可以正常工作(代理通过TMG)。另外,如果我只是通过代理服务器向www.google.com提出GET请求,那么它的工作正常。以下是我尝试使用的代码:

HttpHost httpTargetHost = new HttpHost("www.salesforce.com", 443, "https");
HttpPost httpPost = new HttpPost("/servlet/servlet.WebToLead");

NTCredentials ntCreds = new NTCredentials("proxyUser", "proxyPassword", "workstation", "DOMAIN");

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("proxyHost","proxyPort"), ntCreds );
HttpClientBuilder clientBuilder = HttpClientBuilder.create();

clientBuilder.useSystemProperties();
clientBuilder.setProxy(new HttpHost("proxyHost","proxyPort"));
clientBuilder.setDefaultCredentialsProvider(credsProvider);
clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());

CloseableHttpClient client = clientBuilder.build();
CloseableHttpResponse response = client.execute(httpTargetHost, httpPost);

在回复中,我得到了这个:

2015-01-16 17:33:31,158 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:113) - http-outgoing-0<<需要HTTP / 1.1 407代理身份验证(Forefront TMG需要授权才能完成请求。拒绝访问Web代理筛选器。) 2015-01-16 17:33:31,158 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<<通过:1.1 PROXYHOST 2015-01-16 17:33:31,159 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<<代理验证:协商 2015-01-16 17:33:31,159 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<<代理验证:Kerberos 2015-01-16 17:33:31,159 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<<代理验证:NTLM 2015-01-16 17:33:31,160 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<<连接:关闭 2015-01-16 17:33:31,160 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<<代理连接:关闭 2015-01-16 17:33:31,160 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<< Pragma:没有缓存 2015-01-16 17:33:31,160 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<<缓存控制:无缓存 2015-01-16 17:33:31,161 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<<内容类型:text / html 2015-01-16 17:33:31,161 [main] DEBUG org.apache.http.headers(LoggingManagedHttpClientConnection.java:116) - http-outgoing-0<<内容长度:2699
2015-01-16 17:33:31,164 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator(HttpAuthenticator.java:77) - 需要验证

感谢您提供的任何帮助。

此致 埃里克

1 个答案:

答案 0 :(得分:0)

错误信息说得非常清楚:

  

Forefront TMG需要授权才能完成请求。拒绝访问Web代理筛选器。

您需要某种您未提供的授权。此问题并非特定于Apache HTTPClient。请咨询Forefront TMG安装的管理员,了解您需要的授权(以及凭据)。它可能是您尝试过的一种授权,只有凭据错误或者可能需要其他类型的授权。