php - converting a $_GET cURL request to Laravel 8.x http request not working as expected (returns 403 error)
Get the solution ↓↓↓I have the following cURL request in Postman which works perfectly fine, however I am having issues getting the same response data once I have converted this cURL request into a Laravel 8.x format using the HTTP facade.
curl request
<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://proclubs.ea.com/api/fifa/clubs/info?platform=ps4&clubIds=1741008');
$request->setRequestMethod('GET');
$request->setOptions(array());
$request->setHeaders(array(
'Referer' => 'https://www.ea.com/'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Laravel HTTP request
// have added use Illuminate\Support\Facades\Http; at the top of class
$url = 'https://proclubs.ea.com/api/fifa/clubs/info';
$params = [
'platform' => 'ps4',
'clubIds' => 1741008
];
$response = Http::withHeaders([
'Referrer' => 'https://www.ea.com/',
])->get($url, $params)->json();
dd($response);
expected output
{
"1741008": {
"name": "BanterburyFC",
"clubId": 1741008,
"regionId": 4344147,
"teamId": 112092,
"customKit": {
"stadName": "Wanda Metropolitano",
"kitId": "1836515329",
"isCustomTeam": "0",
"customKitId": "7623",
"customAwayKitId": "7623",
"customKeeperKitId": "5012",
"kitColor1": "1987272",
"kitColor2": "0",
"kitColor3": "16777215",
"kitAColor1": "16734520",
"kitAColor2": "0",
"kitAColor3": "16777215",
"dCustomKit": "0",
"crestColor": "1987272",
"crestAssetId": "99040402"
}
}
}
actual output
null // getting a 403 error response
When running the debug() command in Laravel I can see the following error
old SSL session ID is stale, removing * Mark bundle as not supporting multiuse < HTTP/1.1 403 Forbidden
- how do I fix this?
Answer
Solution:
You have misspelled the header name. It isReferer
with oner
not two. Change your code to this and it should work:
$response = Http::withHeaders([
'Referer' => 'https://www.ea.com/',
])->get($url, $params)->json();
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.