當我在瀏覽器中輸入http://rest.example.com/account/get-balance/27e3xxx/7vvU4c95trfxxxx
並點擊回車時,我得到以下XML響應。PHP GET請求無法正常工作
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
<accountBalance>
<creditLimit>0.0</creditLimit>
<quotaEnabled>true</quotaEnabled>
<value>2.0</value>
</accountBalance>
,但是當我試圖同一個URL裏面PHP是發送響應找不到網頁(糟糕!該網頁不存在。)。這裏有一些方法,我嘗試...
使用SimpleXML
$content = simplexml_load_file($this->request_uri);
使用文件的方法
$content = file_get_contents($this->request_uri);
使用我貼捲曲
// 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.用戶代理 – Peter
@Peter,檢查後會發生什麼?任何提示? –
我的意思是你應該在cURL請求中使用與瀏覽器相同的Cookies,Referer和User。 – Peter