Reputation: 197
I'm testing an XML POST between two files:
index.php, which writes out a simple xml to the page.
send.php, which sends a curl POST to index.php and expects the xml response
The problem occurs when I open 'send.php' - the xml from index.php is not writing to the page. I suspect that I'm not writing out the xml properly, but could really use some guidance on this. My code is below:
// send.php
$url_request = 'index.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url_request);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
$response = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($response);
print_r($xml);
// index.php
header("Content-type: text/xml");
function sendResponse(){
$response = '<?xml version="1.0" encoding="utf-8"?><response>success</response>';
echo $response;
}
sendResponse();
Upvotes: 1
Views: 432
Reputation: 11122
You need to use the full path of the index.php file :
$url_request = 'http://localhost/path/to/index/index.php';
Besides, its is always good practice to use echo curl_error($curl);
after curl_exec
to track errors.
Upvotes: 1