[英]PHP XML Response not showing up in curl request
我正在測試兩個文件之間的XML POST:
index.php,它將簡單的xml寫入頁面。
send.php,它將curl POST發送到index.php,並期望xml響應
當我打開'send.php'時會發生問題-index.php中的xml沒有寫入頁面。 我懷疑我沒有正確地寫出xml,但是確實可以使用一些指導。 我的代碼如下:
// 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();
您需要使用index.php文件的完整路徑:
$url_request = 'http://localhost/path/to/index/index.php';
此外,使用echo curl_error($curl);
永遠是一個好習慣echo curl_error($curl);
在curl_exec
之后跟蹤錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.