2015-07-09 56 views
1

我測試兩個文件之間的XML POST:PHP的XML響應沒有出現在捲曲請求

  1. 的index.php,其寫出一個簡單的XML頁面。當我打開 'send.php'

  2. send.php,它發送一個捲曲POST到的index.php並期望XML響應

,會出現問題 - 從所述的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(); 

回答

1

您需要使用index.php文件的完整路徑:

$url_request = 'http://localhost/path/to/index/index.php'; 

此外,它總是使用echo curl_error($curl);curl_exec後跟蹤誤差很好的做法。

+0

謝謝@KAD,那就是訣竅。非常感激。 – fireinspace

+0

不客氣,老兄 – KAD