问题描述
我正在尝试编写一个PHP脚本,该脚本将POST请求发送到远程服务器,然后解析XML响应.
I'm trying to write a PHP script that sends a POST request to a remote server, then parses the XML response.
我可以执行POST请求,但是(从其他SO问题出发)在解决如何解析XML响应方面遇到困难.
I can do the POST request, but am having difficulty (from other SO questions) working out how to parse the XML response.
我当前的代码给了我:Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "1" in /Users/simon/usercreate.php on line 46
-simplexml_load_file($response)
行.
My current code gives me: Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "1" in /Users/simon/usercreate.php on line 46
- the simplexml_load_file($response)
line.
我正在本地服务器上工作,不确定是否会有所不同.代码:
I'm working on a local server, not sure if that makes a difference. Code:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$response = curl_exec ($curl);
curl_close ($curl);
echo $response;
$rxml = simplexml_load_file($response);
echo $rxml->title;
我在做什么错了?
推荐答案
使用 simplexml_load_string 代替simplexml_load_file
这篇关于PHP:发送POST请求,然后读取XML响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!