【发布时间】:2015-04-23 03:20:55
【问题描述】:
我正在编写一个 SOAP 客户端,使用 org.apache.http.impl.client.CloseableHttpClient 通过代理服务器对外部系统进行 SOAP 调用。
从日志文件看来,通过代理服务器的连接成功,但对外部系统端点的 POST 请求导致 HTTP 400 Bad Request 响应。
我无法弄清楚导致此错误的原因。任何人都可以看看,看看缺少什么?提前感谢您的帮助。
[4/20/15 20:37:04:850 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "POST /Staging/DataTransfer.asmx HTTP/1.1[\r][\n]"
[4/20/15 20:37:04:850 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "SOAPAction: http://data.types.services.ecomm.stores.com/TransferCart[\r][\n]"
[4/20/15 20:37:04:850 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "Content-Type: text/xml[\r][\n]"
[4/20/15 20:37:04:865 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "Accept-Encoding: text/xml[\r][\n]"
[4/20/15 20:37:04:865 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "Content-Length: 2022[\r][\n]"
[4/20/15 20:37:04:865 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "Host: abc.test.com:443[\r][\n]"
[4/20/15 20:37:04:865 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "Connection: Keep-Alive[\r][\n]"
[4/20/15 20:37:04:865 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "User-Agent: Apache-HttpClient/4.4.1 (Java/1.6.0)[\r][\n]"
[4/20/15 20:37:04:865 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "[\r][\n]"
[4/20/15 20:37:04:865 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 >> "TESTDATA"
[4/20/15 20:37:05:099 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 << "HTTP/1.1 400 Bad Request[\r][\n]"
[4/20/15 20:37:05:099 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 << "via: IG Proxy[\r][\n]"
[4/20/15 20:37:05:099 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 << "Date: Tue, 21 Apr 2015 00:37:01 GMT[\r][\n]"
[4/20/15 20:37:05:099 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 << "Server: Microsoft-HTTPAPI/2.0[\r][\n]"
[4/20/15 20:37:05:099 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 << "Connection: Keep-Alive[\r][\n]"
[4/20/15 20:37:05:099 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 << "Content-Type: text/html; charset=us-ascii[\r][\n]"
[4/20/15 20:37:05:099 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 << "Content-Length: 311[\r][\n]"
[4/20/15 20:37:05:099 EDT] 0000001c wire 1 org.apache.http.impl.conn.Wire wire http-outgoing-2 << "[\r][\n]"
当然 - 这是代码:
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(PROXY_HOST, PROXY_PORT),
new UsernamePasswordCredentials(PROXY_USER, PROXY_PASSWORD));
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider).build();
HttpHost target = new HttpHost(ENDPOINT_HOST, 443, "https");
HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT);
RequestConfig config = RequestConfig.custom()
.setProxy(proxy)
.build();
HttpPost httppost = new HttpPost(ENDPOINT_API_URL);
httppost.setConfig(config);
httppost.setHeader("SOAPAction", SOAPAction);
httppost.setHeader("Content-Type", "application/soap+xml;charset=UTF-8;");
httppost.setHeader("Accept-Encoding", "text/xml");
httppost.setEntity(new StringEntity(postBody, "UTF-8"));
//if(LOG.isLoggable(Level.FINE))
LOG.info("Executing request " + httppost.getRequestLine() + " to " + target + " via " + proxy);
CloseableHttpResponse response = httpclient.execute(target, httppost);
LOG.info("CartTransfer HTTP Status=" + response.getStatusLine());
【问题讨论】:
-
请向我们提供帮助您的方法。 TL;DR 发布您的代码。