В моем приложении Laravel 5.8 я использую API с описанием метода:
curl --location --request GET "/api/user" \
--header "Accept: application/json" \
--header "Authorization: Bearer <user access token>"
Но мне не удалось передать параметр токена в GET-запросе в php curl?
Я пытался сделать
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $this->serverApiHosting . '/api/user');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8"));
$resp = curl_exec($ch);
$respArray = json_decode($resp);
Я получил сообщение:
Перенаправление на http://myserver.com/login.
Аналогичная проблема с URL:
curl_setopt($ch, CURLOPT_URL, $this->admindashApi . '/api/user?token=' . $logged_user_token);
Я попробовал как:
curl_setopt($ch, CURLOPT_URL, $this->admindashApi . '/api/user?Authorization=' . 'Bearer '. $logged_user_token);
Но получил ошибку:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
400 Bad Request
Bad Request
Your browser sent a request that this server could not understand.
Apache/2.4.10 (Debian) Server at phpstack-NNN-NNNN.cloudwaysapps.com Port 80
Должен ли я положить его в CURLOPT_HTTPHEADER
?Как я могу это сделать?Какой правильный путь?