蛋糕php http GET与承载密钥?
问题描述:
嗨,我是使用下面的代码来发送HTTPS GET请求,另一个API蛋糕php http GET与承载密钥?
$access_token = $this->Session->read("AUTH_BEARER");
$url = GET_DOCUMENT_BY_ID_URL.'202';
$curl=curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 0);
curl_setopt($curl, CURLOPT_HTTPGET, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$access_token));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);// comment this line in live servers
$response_json=curl_exec($curl);
$error= curl_errno($curl);
$error_message= curl_error($curl);
echo "error:".$error;
echo "<br>";
echo "Error message:".$error_message;
echo "<br>";
curl_close($curl);
$response_array = json_decode($response_json,true);
echo $response_json;
但我没有收到来自服务器的响应。我收到不记名令牌后立即拨打此电话,所以我希望在令牌过期之前拨打了该电话。我在这里做错了什么?有人可以帮我解决这个问题吗?在此先感谢您。注意:我使用的是https://不是http://
答
与cakephp无关,如果您只想发送GET请求,您不需要使用curl,则可以使用file_get_contents像下面的例子
$url = 'http://www.example.com/index.php?xxxx=112';
$options = array('http' => array(
'method' => 'GET',
'header' => 'Authorization: Bearer '.$access_token
));
$context = stream_context_create($options);
$webservice= file_get_contents($url, false, $context);
echo $webservice;
这里如何设置持票人令牌数组(“Authorization:Bearer”。$ access_token) –
检查我的答案我修改 –