java - Apache HttpClient SOAP 请求

标签 java apache soap httpclient

我正在尝试向网络服务发送请求。对于请求,我正在使用此代码。 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)。

感谢您的帮助!

最佳答案

我过去可能也遇到过类似的问题......

就像错误消息中所说的那样:“要调用 Web 服务,请使用服务 URL 而不是 WSDL URL”。

尝试使用浏览器打开 WSDL URL。通常您可以在显示信息的底部找到服务 URL。使用此 URL 作为您的“endpointURL”。

希望我做对了并且可以帮助你:)

关于java - Apache HttpClient SOAP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59141608/

相关文章:

c# - SOAP 使用不同的日期时间格式

objective-c - 将 NSString 参数传递给 SOAP WS 会产生 "Illegal processing instruction target ("xml")"

java - 文本文件号码持有者无法正常工作,如何修复?

Java 代码 无法与安全 openldap 连接?

php - MySQL 用 PHP 递增 int

php - 异步执行 php-script 正在使用经过身份验证的 session

php - 在 Controller 中使用 NuSOAP 的 Laravel 不工作

java - 组合使用不同高级语言编程的两个 webassembly 组件

java - 集成测试+aspectJ+gradle

php - 在 Windows 上更改 documentroot for apache 不起作用