@igorbrum Have you doubled checked the $keyProvider? Does it return everything properly?
Jan 6, 2023
3
Level 1
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!
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.