Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

igorbrum's avatar

PHP cURL to Laravel HTTP Client

Hello, I need help with a conversion from PHP cURL to Laravel HTTP Client.

I have this script:

$keyProvider = new \App\Models\OCIRequest();
$signer = new Signer;
$signer->setKeyProvider($keyProvider);

$url = 'https://iaas.sa-saopaulo-1.oraclecloud.com/20160918/images?compartmentId=ocid1.tenancy.oc1.xyz&limit=801&sortBy=TIMECREATED&sortOrder=DESC&lifecycleState=AVAILABLE';
$method = 'GET';
$headers = $signer->getHeaders($url, $method, null, 'application/json');

$curl = curl_init();

$curlOptions = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 5,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => $method,
    CURLOPT_HTTPHEADER => $headers,
];

curl_setopt_array($curl, $curlOptions);
$response = curl_exec($curl);
echo $response;
curl_close($curl);

This basically retrieve information from Oracle Cloud Infrastructure. The code runs fine using "pure php". However, using Laravel HTTP Client, I received an error (NotAuthenticated). This is the code I have used:

$keyProvider = new \App\Models\OCIRequest();
$signer = new Signer;
$signer->setKeyProvider($keyProvider);

$url = 'https://iaas.sa-saopaulo-1.oraclecloud.com/20160918/images?compartmentId=ocid1.tenancy.oc1.xyz&limit=801&sortBy=TIMECREATED&sortOrder=DESC&lifecycleState=AVAILABLE';
$method = 'GET';
$headers = $signer->getHeaders($url, $method, null, 'application/json');

$response = Http::withHeaders($headers)->get($url);
echo $response->body();

Any advice? Am I missing something? Thank you!

0 likes
3 replies
tisuchi's avatar

@igorbrum Have you doubled checked the $keyProvider? Does it return everything properly?

igorbrum's avatar

@tisuchi Thank you for your response. Yes, I have revised this part, I don't think that's the problem. As I mentioned, I used cURL and it works perfectly.

igorbrum's avatar
igorbrum
OP
Best Answer
Level 1

Just for information (and to close this topic), the error was in the content of $headers. After removing and format properly the content, the error gone away. :)

Please or to participate in this conversation.