简体   繁体   中英

Apache HttpClient SOAP Request

i'm trying to send a request to a webservice. For the requet i'm using this code. The testMessage must be correct, because with SOAPUI the same request is working.

            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();

I always getting a fault response: soap error message I do not understand this message or what should I do... I have the correct wsdl url (it works with SOAPUI).

Thanks for help!

I may have had a similar problem in the past...

Like it says in your error message: "To call the Webservice use the service URL instead of the WSDL URL".

Try to open the WSDL URL with your browser. Usually you can find the SERVICE URL at the bottom of the displayed information. Use this URL as your "endpointURL".

Hope I got it right and could help you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM