Tuesday 8 April 2014

Using PHP CURL XML Request and get XML Response

<?php
$xml = '<ProductProvisionRequest>
    <requisitionID>4183</requisitionID>
    <orderExternalReferenceID>200000353</orderExternalReferenceID>
    <submissionDate>1395393241</submissionDate>
    <shopperPassword></shopperPassword>
    <shopperInfo>
        <userKey>
            <userID>test@nonesbservice-pro-21-3-2015-2.com</userID>
            <externalReferenceID></externalReferenceID>
            <companyID>Rosetta Stone</companyID>
            <loginID>test@snonesbservice-pro-21-3-2015-2.com</loginID>
            <siteID>rstUS</siteID>
        </userKey>
    </shopperInfo>
    <orderExtendedAttributes>
        <item>
            <name></name>
            <value></value>
            <datatype></datatype>
        </item>
    </orderExtendedAttributes>
    <lineItemLevelRequest>
       
    </lineItemLevelRequest>
</ProductProvisionRequest>';
$ch = curl_init();
$url = 'www.abc.com';
curl_setopt($ch, CURLOPT_URL, $url); //set to url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // tell curl to return data in a variable
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","header-tocken"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); // post the xml
//curl_setopt($ch, CURLOPT_TIMEOUT, (int)3000000); // set timeout in seconds
$xmlResponse = curl_exec($ch);
echo "<pre>";
print_r($xmlResponse);
curl_close($ch); 
?>

No comments:

Post a Comment