You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Xue, Xiaohui" <xi...@sap.com> on 2012/03/13 21:10:24 UTC

Setting SOAPAction in HTTPPost header

Hi All,

I'm sending a SOAP request that requires to set a SOAPAction header.
Below is my code that I thought being correct. However, my WebServices server keeps on telling me that there's no SOAP Action..

I have tried in Fiddler to compose the same request, and by putting SOAPAction header in the composer, the server is able to return me the correct answer.
Is my code of setup SOAPAction header not correct? Please note that I'm using HTTPClient 4.0.3.

Any helps are welcome.

Thanks!
Xiaohui

My code:
                HttpClient httpClient = new DefaultHttpClient();
                httpClient.getParams().setParameter("Content-Type", "text/xml; charset=utf-8");
                httpClient.getParams().setParameter("SOAPAction", "mySOAPAction");

                String body = mySOAPBody";
                StringEntity requestBody = new StringEntity(body, "utf-8");
                requestBody.setContentType(new BasicHeader("Content-Type", "text/xml"));

                HttpPost request = new HttpPost(url);
                request.setEntity(requestBody);
                HttpResponse response = httpClient.execute(httpHost, request);

Server response:
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode><faultstring>no SOAPAction header!</faultstring><detail><ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">CRDB-DBSERVER</ns2:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>




Re: Setting SOAPAction in HTTPPost header

Posted by William Speirs <ws...@apache.org>.
Setting the params of the client is not what you want. You want to set a
header in the request. Something more like:

request.setHeader("SOAPAction", "mySOAPAction"); // [1]

[1]
http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/message/AbstractHttpMessage.html#setHeader(java.lang.String,
java.lang.String)

Bill-

On Tue, Mar 13, 2012 at 4:10 PM, Xue, Xiaohui <xi...@sap.com> wrote:

> Hi All,
>
> I'm sending a SOAP request that requires to set a SOAPAction header.
> Below is my code that I thought being correct. However, my WebServices
> server keeps on telling me that there's no SOAP Action..
>
> I have tried in Fiddler to compose the same request, and by putting
> SOAPAction header in the composer, the server is able to return me the
> correct answer.
> Is my code of setup SOAPAction header not correct? Please note that I'm
> using HTTPClient 4.0.3.
>
> Any helps are welcome.
>
> Thanks!
> Xiaohui
>
> My code:
>                HttpClient httpClient = new DefaultHttpClient();
>                httpClient.getParams().setParameter("Content-Type",
> "text/xml; charset=utf-8");
>                httpClient.getParams().setParameter("SOAPAction",
> "mySOAPAction");
>
>                String body = mySOAPBody";
>                StringEntity requestBody = new StringEntity(body, "utf-8");
>                requestBody.setContentType(new BasicHeader("Content-Type",
> "text/xml"));
>
>                HttpPost request = new HttpPost(url);
>                request.setEntity(requestBody);
>                HttpResponse response = httpClient.execute(httpHost,
> request);
>
> Server response:
> <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="
> http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="
> http://www.w3.org/2001/XMLSchema" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode
> xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode><faultstring>no
> SOAPAction header!</faultstring><detail><ns2:hostname xmlns:ns2="
> http://xml.apache.org/axis/
> ">CRDB-DBSERVER</ns2:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
>
>
>
>