2015-07-09 80 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