I'm trying to make a GET request using curl in php with the code below.
test.php
$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://apiaddress/collection', CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array( 'Authorization: Bearer 374dad6fdc005a0f17c49aeg77rbifuy48t7205hfhf7he8857c' ), CURLINFO_HEADER_OUT => true )); $response = curl_exec($curl); $err = curl_error($curl); $info = curl_getinfo($curl, CURLINFO_HEADER_OUT); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($err) { echo "cURL Error #:" . $err; } else { echo "Response code: " . $httpCode . "\nResponse body: \n" . $response . "\n"; } curl_close($curl); echo $info; This request works in Postman and works using this curl command curl -X GET \ https://apiaddress/collection -H 'Authorization: Bearer 374dad6fdc005a0f17c49aeg77rbifuy48t7205hfhf7he8857c', but when I run php test.php in the cli I get this output. I'm guessing I'm missing a header or sending an incorrect header somewhere?
Response code: 401
Response body:
{"type":"https://apiaddress/errors#error-unauthorized","title":"Unauthorized","detail":"No authorization credentials provided. You must provide an authorization token for this request.","status":401}
GET /collection HTTP/2
Host: apiaddress
Accept: */*
Authorization: Bearer 374dad6fdc005a0f17c49aeg77rbifuy48t7205hfhf7he8857c
$infocontain?$infois the output above that starts with GETContent-Typein your PHP request.