récupérer un header dans un fichier texte avec curl
Bonjour à tous,
J'essaye de m'authentifier à une API et rencontre un problème.
Alors voila l'authentification se passe bien, je créer un fichier texte et dedans écrit le header récupéré pour cette authentification grâce à CURLOPT_WRITEHEADER.
Voici à quoi cela ressemble à l'intérieur de mon fichier texte :
Citation:
HTTP/1.1 200
Bearer: <N.?|T,*V=bpc&VKU:5wxA%_d2SM;*t@2^2X/<doA7lh(jz}[:co?(j]i1A9?rTzXF9Po9CW[;TPyghw13NROMxN}7<ACreRmrzKk6[<zI9{*rz*@/3Ae$O_Oc|:*L.Nde20*$/Iu$xOb5sZ{eVa@'g=jc=SOU$Ilc.X,NruIwocWq]Rx3H*$Wlk=cvc<vOYg4UcNdkoSYV.pDNG{Uf>~{_QjOc2N%SZv5PWmgw>xaC*r~F;Zi/t|&<?:[dpu-
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Length: 0
Date: Thu, 16 Jan 2020 14:28:02 GMT
Maintenant j'aimerai le récupérer pour pouvoir accéder aux autres fonctionnalités de l'API. Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| $curl = curl_init();
//$file_header= fopen('headers.txt', 'r');
$file_header = file_get_contents('headers.txt');
curl_setopt_array($curl, array(
CURLOPT_URL => "http://monUrl",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array($file_header),
));
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
echo $http_code; |
Cependant cela me renvoie 400. Je ne comprends pas quelqu'un pourrait m'aider ?
Un grand merci à tous !