我必须重现这个流程:
页面request.php调用页面response.php卷曲附加xml - >页面响应读取附加的xml并打印另一个xml - >页面请求读取并打印响应。
这是我用于页面request.php的代码:
$xmlRequest = '<Main >
<First>
<Second>
Detail 1
</Second>
<Second>
Detail 2
</Second>
</First>
</Main>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost:8888/response.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
$server_output = curl_exec ($ch);
curl_close ($ch);
echo "Result :".$server_output;
在page response.php中,我无法检索刚从request.php发送的xml
header('Content-type: application/xml');
var_dump($_REQUEST);
Var_dump
返回空值,print_r($_REQUEST)
也是如此。
如何阅读发送的XML?
答案 0 :(得分:1)
FROM:phpdocs,CURLOPT_POSTFIELDS
必须是数组/ urlencoded字符串。请注意,如果使用数组Content-Type
必须为multipart/form-data
。这是一个例子。我希望这会有所帮助。
$postFields = array ( 'xml' => '<Main><First><Second>Detail 1</Second><Second>Detail 2</Second></First></Main>',);
...
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
...
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
...