【发布时间】:2012-08-24 16:19:08
【问题描述】:
当我在浏览器中输入http://rest.example.com/account/get-balance/27e3xxx/7vvU4c95trfxxxx 并回车时,我得到以下 XML 响应。
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
<accountBalance>
<creditLimit>0.0</creditLimit>
<quotaEnabled>true</quotaEnabled>
<value>2.0</value>
</accountBalance>
但是当我在 PHP 中尝试相同的 URL 时,它发送的响应是找不到页面(糟糕!那个页面不存在。)。以下是我尝试的几种方法...
使用 SimpleXML
$content = simplexml_load_file($this->request_uri);
使用文件方法
$content = file_get_contents($this->request_uri);
使用 CURL
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $this->request_uri);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
$content = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
-
$this->request_uri= 我在浏览器中粘贴的相同 URL。我哪里错了?请帮助我。谢谢。
【问题讨论】:
-
同意。检查:1.cookies 2.referer 3.user-agent
-
@Peter,检查后会发生什么?有什么提示吗?
-
我的意思是你应该在 cURL 请求中使用与浏览器相同的 Cookie、Referer 和 User