Reputation: 278
I have following REQUEST TO SEND in xml. I want to send it in php. Can you help me how to write php curl function to send following xml ?
POST /xml/ HTTP/1.0
Content-Type: text/xml;charset=utf-8
Content-Length: 839
Accept: text/xml
Accept-Encoding: gzip
Authorization: <BASIC AUTH CREDENTIALS HERE>
User-Agent: <YOUR SOFTWARE VERSION HERE>
Host: webservices.securetrading.net
Connection: close
<requestblock version="3.67">
<alias>[email protected]</alias>
<request type="AUTH">
<operation>
<sitereference>test_site12345</sitereference>
<accounttypedescription>ECOM</accounttypedescription>
</operation>
<merchant>
<orderreference>Example AUTH</orderreference>
<termurl>https://www.example.com/termurl.cgi</termurl>
<name>Test Merchant</name>
</merchant>
<customer>
<ip>1.2.3.4</ip>
</customer>
<billing>
<amount currencycode="GBP">2115</amount>
<town>Bangor</town>
<country>GB</country>
<payment type="VISA">
<expirydate>10/2031</expirydate>
<pan>4111111111111111</pan>
<securitycode>123</securitycode>
</payment>
</billing>
<settlement/>
</request>
</requestblock>
need help from php professional.
Upvotes: 1
Views: 810
Reputation: 3658
Here is sample you can send as xml data using curl
$url="http://"; // Enter url here
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "<requestblock version=\"3.67\">\r\n <alias>[email protected]</alias>\r\n <request type=\"AUTH\">\r\n <operation>\r\n <sitereference>test_site12345</sitereference>\r\n <accounttypedescription>ECOM</accounttypedescription>\r\n </operation>\r\n <merchant>\r\n <orderreference>Example AUTH</orderreference>\r\n <termurl>https://www.example.com/termurl.cgi</termurl>\r\n <name>Test Merchant</name>\r\n </merchant>\r\n <customer>\r\n <ip>1.2.3.4</ip>\r\n </customer>\r\n <billing>\r\n <amount currencycode=\"GBP\">2115</amount>\r\n <town>Bangor</town>\r\n <country>GB</country>\r\n <payment type=\"VISA\">\r\n <expirydate>10/2031</expirydate>\r\n <pan>4111111111111111</pan>\r\n <securitycode>123</securitycode>\r\n </payment>\r\n </billing>\r\n <settlement/>\r\n </request>\r\n</requestblock>",
CURLOPT_HTTPHEADER => array(
"accept-encoding: application/gzip",
"content-type: text/xml"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Upvotes: 1