I am trying to send a GET request to a python server with an Authorization Token in the header.
I do receive the Request on the server side but without the authorization token
Here is the php code that is generating the request :
<?php
$url = "http://localhost:7432/f.php";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Authorization: sdfascvthsgdgdssgvsgscf",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
When I generate the request from Reqbin, I do Receive the request with the Authorization token in the header , but when I try to generate the request from the php file then it does not send the Authorization token to the server
Here is the request received on server side when I use the Reqbin website to make the request:
127.0.0.1 - - [03/Sep/2021 13:27:10] "GET /f.php HTTP/1.1" 200 -
Host: localhost:7432
Connection: keep-alive
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="92", "Opera";v="78"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159
Safari/537.36 OPR/78.0.4093.184
sec-ch-ua-mobile: ?0
Authorization: sdfascvthsgdgdssgvsgscf
Accept: */*
Sec-Fetch-Site: none
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: _ga=GA1.1.1359401486.1622671713
And This is the received Request when I use the php code mentioned above :
127.0.0.1 - - [03/Sep/2021 13:27:20] "GET /f.php HTTP/1.1" 200 -
Host: localhost:7432Connection: keep-alive Cache-Control: max-age=0
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="92", "Opera";v="78"
sec-ch-ua-mobile: ?0 Upgrade-Insecure-Requests: 1 User-Agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/92.0.4515.159 Safari/537.36 OPR/78.0.4093.184
Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: none Sec-Fetch-Mode: navigate Sec-Fetch-User: ?1
Sec-Fetch-Dest: document Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9 Cookie:
_ga=GA1.1.1359401486.1622671713
What am I doing wrong at the php side ?
My Answer:
It looks like you are not setting the `CURLOPT_HTTPGET` option in your cURL request. This option tells cURL to use a GET request instead of the default POST request.
You can add the following line to your code before `curl_exec($curl)`:
php
curl_setopt($curl, CURLOPT_HTTPGET, true);
This should ensure that the Authorization token is included in the header of the GET request.
Rate this post
3 of 5 based on 5633 votesComments