【发布时间】:2019-12-02 15:04:03
【问题描述】:
我正在尝试向网络服务发送请求。对于请求,我正在使用此代码。 testMessage 必须是正确的,因为使用 SOAPUI 时,相同的请求正在工作。
StringEntity stringEntity = new StringEntity(testMessage, "UTF-8");
stringEntity.setChunked(true);
String endpointURL = "http://host:8000/wsdl";
String soapAction = "urn:anyAction";
HttpPost httpPost = new HttpPost(endpointURL);
httpPost.setEntity(stringEntity);
httpPost.addHeader("Accept-Encoding", "gzip,deflate");
httpPost.addHeader("Content-Type:", "text/xml;charset=UTF-8");
httpPost.addHeader("SOAPAction", soapAction);
String authorization = "user:pass";
String header = "Basic " + new String(Base64.getEncoder().encode(authorization.getBytes()));
httpPost.addHeader("Authorization", header);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
我总是收到错误响应: soap error message 我不明白这条消息或我应该怎么做......我有正确的 wsdl url(它适用于 SOAPUI)。
感谢您的帮助!
【问题讨论】:
-
错误消息说不要使用 wsdl URL。 SoapUI 可能正在这样做,这就是它工作的原因。如果您可以将 SoapUI 和您的程序发布的实际消息进行比较,那么调试一定更容易(尝试 Fiddler)。另外为什么不使用库,这样您就不需要执行(和调试)这个核心任务?春天可能是你的朋友
-
感谢您的回复。我的客户必须尽可能小而简单。我只需要提交两三个条目。所以我不想使用 Spring。
标签: java apache soap httpclient