簡體   English   中英

Apache HttpClient SOAP 請求

[英]Apache HttpClient SOAP Request

我正在嘗試向網絡服務發送請求。 對於請求,我正在使用此代碼。 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 錯誤消息我不明白此消息或我該怎么辦...我有正確的 wsdl url(它適用於 SOAPUI)。

感謝幫助!

我過去可能遇到過類似的問題...

就像您的錯誤消息中所說的那樣:“要調用 Web 服務,請使用服務 URL 而不是 WSDL URL”。

嘗試使用瀏覽器打開 WSDL URL。 通常您可以在顯示信息的底部找到 SERVICE URL。 將此 URL 用作您的“endpointURL”。

希望我做對了,可以幫助你:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM