Iman
Iman

Reputation: 73

Send SOAP request using CURL

I am sending a soap request using PHP curl(). I need to print my request, so that I can have a look into my request and understand weather it is going in a right format.

Here is my code:

$parameters = "<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ejb='http://ejb.gateway.ebpp.fawryis.com/'>
   <soapenv:Header/>
   <soapenv:Body>
      <ejb:process>
//... 
      </ejb:process>
   </soapenv:Body>
</soapenv:Envelope>";


$url='//URL to the service';
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_ENCODING,'utf-8');
curl_setopt($curl,CURLOPT_HTTPHEADER,array (
    'SOAPAction:""', 
    'Content-Type: text/xml; 
    charset=utf-8',
));

curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $parameters);
$result = curl_exec($curl);

I get a wrong data sent error from the API side which means I am not sending a correct format. Can anyone please let me know how to do that?

Update: Verbose information

* About to connect() to 10.2.250.4 port 9081 (#0)
*   Trying 10.2.250.4...
* connected
* Connected to 10.2.250.4 (10.2.250.4) port 9081 (#0)
> POST /CoreWeb/ApplicationBusinessFacadeService HTTP/1.1
Host: 10.2.250.4:9081
Accept: */*
Accept-Encoding: utf-8
SOAPAction:""
Content-Type: text/xml; 
    charset=utf-8
Content-Length: 1087
Expect: 100-continue

< HTTP/1.1 100 Continue
< Content-Length: 0
< Date: Thu, 20 Mar 2014 14:04:19 GMT
< Server: WebSphere Application Server/7.0
< HTTP/1.1 200 OK
< Date: Thu, 20 Mar 2014 14:04:19 GMT
< Server: WebSphere Application Server/7.0
< Content-Type: text/xml; charset=utf-8
< Content-Language: en-US
< Content-Length: 914
< 
* Connection #0 to host 10.2.250.4 left intact

Upvotes: 2

Views: 8377

Answers (1)

Sabuj Hassan
Sabuj Hassan

Reputation: 39355

Your Header is broken into two lines:

'Content-Type: text/xml; 
charset=utf-8',

Make it in one line. May be it is causing the problem for you.

'Content-Type: text/xml;charset=UTF-8',

UPDATE:

curl_setopt($curl,CURLOPT_HTTPHEADER,array (
   'SOAPAction:""', 
   'Content-Type: text/xml;charset=utf-8',
   'Expect:'
));

Upvotes: 2

Related Questions