【发布时间】:2015-01-16 22:56:31
【问题描述】:
我在通过 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 2015-01-16 17:33:31,164 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator(HttpAuthenticator.java:77) - 需要身份验证
感谢您提供的任何帮助。
问候, 埃里克
【问题讨论】:
-
我想补充一点的是,当我不需要通过 TMG 时,POST 可以正常工作。
标签: apache proxy apache-httpclient-4.x