PHP:发送 POST 请求然后读取 XML 响应?
我正在尝试编写一个 PHP 脚本,将 POST 请求发送到远程服务器,然后解析 XML 响应。
我可以执行 POST 请求,但是(从其他 SO 问题)我很难弄清楚如何解析 XML 响应。
我当前的代码给了我: Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load externalEntity "1" in /Users/simon/usercreate.php on line 46< /code> -
simplexml_load_file($response)
行。
我正在本地服务器上工作,不确定这是否有影响。代码:
$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;
我做错了什么?
I'm trying to write a PHP script that sends a POST request to a remote server, then parses the XML response.
I can do the POST request, but am having difficulty (from other SO questions) working out how to parse the XML 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;
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 simplexml_load_string 而不是
simplexml_load_file
use simplexml_load_string instead of
simplexml_load_file
您必须设置 cURL 选项才能返回传输
You have to set the cURL option to return the transfer
您想要加载一个字符串,而不是加载一个文件。
Instead of loading a file, you want to load a string.