我试图在php中获取curl -X GET --header "Accept: application/json" --header "authorization: Bearer <API token>" "https://api.clashofclans.com/v1/clans?name=%23P8PQ8VL2"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clashofclans.com/v1/clans?name=%23P8PQ8VL2");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'authorization: Api key'
));
$result=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($result, true));
这是我第一次在php中使用curl,提前感谢:)
答案 0 :(得分:0)
您正在使用第二组选项覆盖标题。我会像这样建立头数组:
$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "authorization: Bearer " . $yourAPItoken;
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
发送数组:
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
答案 1 :(得分:0)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);