I need to post to a client's URL (in case it matters the client is on a .Net platform) using SOAP and XML. The request needs to look something like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" xmlns:XXX="http://schemas.datacontract.org/2004/07/XXXAPI.Entities.XXX" xmlns:XXX1="http://schemas.datacontract.org/2004/07/XXXAPI.Entities.Admin"> <soap:Header/> <soap:Body>
<tem:SaveXXXStatus>
<!--Optional:-->
<tem:req>
<!--Optional:-->
<XXX:AWBNumber>69184678146</XXX:AWBNumber>
<!--Optional:-->
… etc. …
<!--Optional:-->
<XXX:pincode></XXX:pincode>
</tem:req>
<!--Optional:-->
<tem:profile>
<!--Optional:-->
<XXX1:Api_type>S</XXX1:Api_type>
<!--Optional:-->
<XXX1:Area></XXX1:Area>
<!--Optional:-->
<XXX1:LicenceKey>xxxxxxxxxxxxxxxxxxx</XXX1:LicenceKey>
<!--Optional:-->
<XXX1:LoginID>XXXYYY</XXX1:LoginID>
<!--Optional:-->
<XXX1:Version>1</XXX1:Version>
</tem:profile>
</tem:SaveXXXStatus> </soap:Body> </soap:Envelope>
I am using the following code:
$ch = curl_init();
//var_dump($ch);
curl_setopt($ch, CURLOPT_URL,"https://example.com?wsdl");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'tem:"http://tempuri.org/"',
'Content-Type: text/xml',
'XXX:"http://schemas.datacontract.org/2004/07/XXXAPI.Entities.XXX"'
'XXX1:"http://schemas.datacontract.org/2004/07/XXXAPI.Entities.Admin"'
));
//curl_setopt($ch, CURLOPT_USERPWD, "XXXYYY:xxxxxxxxxxxxx"); //Probably not needed
curl_setopt($ch, CURLOPT_POST, 1);
$strRequest = "";
$strRequest .= "AWBNumber=69184678161";
… etc….
$strRequest .= "&pincode=";
$strRequest .= "&Api_type=S";
$strRequest .= "&Area=";
$strRequest .= "&LicenceKey=xxxxxxxx";
$strRequest .= "&LoginID=XXXYYY";
$strRequest .= "&Version=1";
curl_setopt($ch, CURLOPT_POSTFIELDS,$strRequest);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
var_dump($server_output);
This post shows that the header (envelope etc.) can simply be added to the POSTFIELDS string but I tried that and it didn't work. Besides it seems like such a hack!
Anyway, no combination is working - I am getting a zero length string as a result ($server_output). What is the right way to pass the headers and what else needs to be fixed here?