Send XML data to webservice using php curl
After Struggling a bit with Arzoo International flight API, I've finally found the solution and the code simply works absolutely great with me. Here are the complete working code:
//Store your XML Request in a variable
$input_xml = '<AvailRequest>
<Trip>ONE</Trip>
<Origin>BOM</Origin>
<Destination>JFK</Destination>
<DepartDate>2013-09-15</DepartDate>
<ReturnDate>2013-09-16</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
<Currency>INR</Currency>
<PreferredClass>E</PreferredClass>
<Eticket>true</Eticket>
<Clientid>777ClientID</Clientid>
<Clientpassword>*Your API Password</Clientpassword>
<Clienttype>ArzooINTLWS1.0</Clienttype>
<PreferredAirline></PreferredAirline>
</AvailRequest>';
Now I've made a little changes in the above curl_setopt declaration as follows:
$url = "http://59.162.33.102:9301/Avalability";
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
curl_setopt($ch, CURLOPT_POSTFIELDS,
"xmlRequest=" . $input_xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
curl_close($ch);
//convert the XML result into array
$array_data = json_decode(json_encode(simplexml_load_string($data)), true);
print_r('<pre>');
print_r($array_data);
print_r('</pre>');
That's it the code works absolutely fine for me. I really appreciate @hakre & @Lucas For their wonderful support.
Send an XML post request to a web server with CURL
Try it this way:
$url = 'https://android.googleapis.com/gcm/send';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, "<xml>here</xml>" );
$result = curl_exec($ch);
curl_close($ch);
For more details visit: http://php.net/manual/en/function.curl-setopt.php
how to send xml to web service with php
$url = 'http://webservice/example/user';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/xml',
'Content-Length: ' . strlen($data))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responses = curl_exec($ch);
curl_close($ch);
In PHP how to send signed xml as soap request using curl
Code
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
replaced with
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('soapRequest.xml'))
And it started working fine.
Instead of specifying value of file in $message variable and then setting $message in CURLOPT_POSTFIELDS, now using file_get_contents() to read file and set CURLOPT_POSTFIELDS.
Taken hint from PHP cURL: how to set body to binary data?
Related Topics
How to Populate HTML Dropdown List with Values from Database
Downloading Attachments to Directory with Imap in PHP, Randomly Works
Php:Binary Image Data, Checking the Image Type
Replace the Variable Price Range by the Chosen Variation Price in Woocommerce 4+
Checking If Process Still Running
Best Way to Avoid Code Injection in PHP
What Is the Best Practice to Use When Using PHP and HTML
Getting All Values from H1 Tags Using PHP
Deny Ajax File Access Using Htaccess
How to Send a Data to a Web Server from Android
Php:: How Long to Tmp Files Stay
Laravel 5.4 - Validation with Regex
Php: Setting a Timezone by Utc Offset
Easiest Way to Alternate Row Colors in PHP/Html
Codeigniter Session Data Lost After Redirect