1
我嘗試做以下捲曲要求:使捲曲要求給Google的OAuth API
$url = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=$access_token";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_VERBOSE, true);
$resp = curl_exec($ch);
echo $resp; //prints 'Not found'
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $httpCode; //prints '404'
curl_close($ch);
第一echo
打印「未找到」,第二次印刷「404」。不過,如果我做echo "$url?$params"
,並複製輸出到瀏覽器的地址欄,頁面將打開。不知道什麼可以導致Not found
正確的網址。有人能告訴我我做錯了什麼嗎?
預先感謝您!
UPD。這裏的curl_getinfo()
轉儲:
array(20) { ["url"]=> string(45) "https://www.googleapis.com/oauth2/v1/userinfo"
["content_type"]=> string(24) "text/html; charset=UTF-8" ["http_code"]=> int(404)
["header_size"]=> int(360) ["request_size"]=> int(218) ["filetime"]=> int(-1)
["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=>
float(0.657275) ["namelookup_time"]=> float(0.00257) ["connect_time"]=> float(0.162467)
["pretransfer_time"]=> float(0.495426) ["size_upload"]=> float(0) ["size_download"]=>
float(9) ["speed_download"]=> float(13) ["speed_upload"]=> float(0)
["download_content_length"]=> float(0) ["upload_content_length"]=> float(0)
["starttransfer_time"]=> float(0.657247) ["redirect_time"]=> float(0) }
您確定您在代碼中的$ url結尾處添加了一個問號嗎? – Ignas
向我們展示來自curl_getinfo的所有信息。順便說一下,在您的瀏覽器中使用GET,並在上面的代碼中使用POST。 – Nin
@ Nin,謝謝你的回答。更新了問題。 '$ curl_post' if'false',我在做GET請求 – Eugeny89