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