displaying response text after xml request using curl in php
Posted: Wed Feb 13, 2013 3:39 am
Hi,
I am stuck with something that is very important to fix asap.
I basically want to display the content of the response received
after xml request post in CURL. I am able to receive several info
regarding the request. However, I do not find any reference to
display the content of the received response. I know that the length
of the xml response is 1793. Which I verified manually in notepad++.
However, more importantly I wish to echo/print_r the response in php
webpage. Please help.
My codes are as per below:
<?php
$requestXML = "<XML><header><code>SAMPLEFIN6</code><version>0</version><count>1</count><timesent>20120518122033</timesent></header><data><startdate>20110101</startdate><enddate>20110131</enddate><airport>TESTAIRPORT</airport></data></XML>";
$server = 'http://123.123.123.123:8002';
$server = 'http://localhost:8002';
$headers = array(
"Content-type: text/xml"
,"Content-length: ".strlen($requestXML)
,"Connection: close"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
$result = curl_getinfo($ch);
$httpResponseCode = $result['http_code'];
if(curl_errno($ch)){
print curl_error($ch);
echo " something went wrong..... try later";
}else{
curl_close($ch);
//echo 'hiiii';
echo '<pre>';
print_r($result);
echo '</pre >';
}
echo 'The response size is: '.$result[download_content_length];
?>
I am stuck with something that is very important to fix asap.
I basically want to display the content of the response received
after xml request post in CURL. I am able to receive several info
regarding the request. However, I do not find any reference to
display the content of the received response. I know that the length
of the xml response is 1793. Which I verified manually in notepad++.
However, more importantly I wish to echo/print_r the response in php
webpage. Please help.
My codes are as per below:
<?php
$requestXML = "<XML><header><code>SAMPLEFIN6</code><version>0</version><count>1</count><timesent>20120518122033</timesent></header><data><startdate>20110101</startdate><enddate>20110131</enddate><airport>TESTAIRPORT</airport></data></XML>";
$server = 'http://123.123.123.123:8002';
$server = 'http://localhost:8002';
$headers = array(
"Content-type: text/xml"
,"Content-length: ".strlen($requestXML)
,"Connection: close"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
$result = curl_getinfo($ch);
$httpResponseCode = $result['http_code'];
if(curl_errno($ch)){
print curl_error($ch);
echo " something went wrong..... try later";
}else{
curl_close($ch);
//echo 'hiiii';
echo '<pre>';
print_r($result);
echo '</pre >';
}
echo 'The response size is: '.$result[download_content_length];
?>