我可以发送GET
请求并在以下行收到回复。
$curl_resp = curl_exec($curl);
我使用以下内容来解析响应,但它不起作用,我已手动将某些值设置为$curl_resp
,但仍不确定如何分别访问xml
的每个标记的值
$xml = simplexml_load_string($curl_resp);
注意:我收到了实际的xml,但无法解析它,(我需要在变量中单独获取每个标记的值)
代码:
<?php
$service_url = ' The Url goes here';
$curl = curl_init($service_url);
$curl_post_data = array(
"PASSWORD" => 'pass',
"USERNAME" => 'username'
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_resp = curl_exec($curl);
curl_close($curl);
答案 0 :(得分:2)
您的变量$curl_response
与$curl_resp
不同(您要解析的内容)
您可以像访问任何其他数组一样访问每个标记的值。
答案 1 :(得分:1)
如果未设置CURLOPT_RETURNTRANSFER
选项,则您的$curl_resp
将返回true/false
。
如果已设置,则可能会返回false
或格式不正确的xml string
。如果您发布更多代码或实际的卷曲响应文本,我们可能会提供更多信息。
编辑:
阅读代码后,您似乎将响应文本分配给$ curl_response而不是$ curl_resp
答案 2 :(得分:-1)
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "your url");
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);