Reputation: 3731
I'm trying to do the following curl request:
$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);
first echo
prints 'Not found', second prints '404'. Still, if I do echo "$url?$params"
, and copy outputed url to adress bar of browser, the page will open. Have no idea what can cause Not found
on correct url. Can someone tell me what I'm doing wrong?
Thank you in advance!
UPD. here's dump of 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) }
Upvotes: 1
Views: 2367
Reputation: 3010
Try this:
$url = "https://www.googleapis.com/oauth2/v1/userinfo";
$params = "access_token=$access_token";
$ch = curl_init($url . '?' . $params);
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_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($ch);
echo $resp; //prints 'Not found'
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $httpCode; //prints '404'
curl_close($ch);
Now you're sending using GET and you ignore the SSL cert.
Upvotes: 4