将 $_GET cURL 请求转换为 Laravel 8.x http 请求未按预期工作(returns 403 错误)

converting a $_GET cURL request to Laravel 8.x http request not working as expected (returns 403 error)

我在 Postman 中有以下 cURL 请求,它工作得很好,但是当我使用HTTP 外观。

卷曲请求

<?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 请求

//已添加使用Illuminate\Support\Facades\Http;在 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);

预期输出

{
    "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"
        }
    }
}

实际产量

null // getting a 403 error response

当 运行 在 Laravel 中执行 debug() 命令时,我可以看到以下错误

old SSL session ID is stale, removing * Mark bundle as not supporting multiuse < HTTP/1.1 403 Forbidden - 我该如何解决这个问题?

您拼错了 header 名字。它是 Referer,一个 r 而不是两个。将您的代码更改为此,它应该可以工作:

$response = Http::withHeaders([
    'Referer' => 'https://www.ea.com/',
])->get($url, $params)->json();