Error in Content-Length Header Configuration

Asked 2 years ago, Updated 2 years ago, 55 views

I have no experience with the server, and I have to use the progress bar to get the communication status, so to get the data capacity
To resolve this issue by setting the Content-Length header, we edited the code as follows:

$result=$games
    ->map(function($game){
        return [
            'id' = > $game->id,
            'date' = > $game->date,
            'team_id' = > $game->team_id,
            'team_name' = > $game->team_name,
            'opponent_id' = > $game->opponent_team_id,
            'opponent_team' = > $game->opponent_team_name,
            'win_or_loss' = > $game->win_or_loss,
            'is_field_first' =>$game->is_field_first,
            'runs_scored' = > $game->runs_scored,
            'runs_allowed' = > $game->runs_allowed,
            'tournament' = > $game->tournament,
            'is_aggregated' = > $game-> is_aggregated,
            'is_aggregating' = > $game-> is_aggregating,
            'has_draft' = > $game->hasDraft(),
            'updated_at' = > $game->updated_at->formatLocalized ('%Y-%m-%d%H:%M:%S'),
        ];
    })
    ->values();
$gameData=[];
$gameData['games'] = $result;
return response ($gameData)
    ->header('Content-Length:'.strlen(json_encode($result->toArray()));

However, I got the following error

local.ERROR: Type error: Too few arguments to function Illuminate\Http\Response::header(), 1 passed in /home/ec2-user/escore/www/app/Http/Controllers/Api/GroupController.php on line 105 and at least 2 expected {"userId":1185,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: Too few arguments to function Illuminate\\Http\\Response::header(), 1 passed in/home/ec2-user/escore/www/app/Http/Controllers/Api/GroupController.php on line 105 and at least 2 expected at/home/ec2-user/escore/www/vendor/larvel/framework/src/Illumpense)—Rumpse: 65 

The capacity cannot be acquired.
There is an error if the argument is insufficient, but I don't know where and what to set.
The code is created in laravel.

Do you know how to solve this problem?
This may be a rudimentary question, but I appreciate your cooperation.

php laravel

2022-09-30 17:57

1 Answers

As you can see in the error, the header method does not have enough.
The first argument appears to be the name of the header and the second argument appears to contain a value.

return response($gameData)
    ->header('Content-Length', strlen(json_encode($result->toArray()));

This is not limited to this, but you should first refer to the documentation for any unclear points about the framework or library or how to use the correct method.Most documents have instructions on how to use them.

HTTP Response 5.5 Ravel


2022-09-30 17:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.