in my laravel project, POST requests sometimes return code 302 and sometimes code 200
When the 302 code is returned, everything is correct.
But sometimes the 200 code is returned and this causes the POST data to be printed on the page and cookies/sessions are not set, But then, the SUBSCRIBE method codes are executed and the redirect is done.
This problem occurs in all POST requests, only occasionally.
And this problem only happens on the real server
How can this problem be solved?
form
<form action="{{ route('subscribe.save') }}" method="post">
@csrf
<input name="email" type="text" placeholder="enter email">
<input type="submit" value="submit">
</form>
controller
public function subscribe(Request $request)
{
$request->validate([
'email' => 'required'
]);
Subscribe::create([
'email' => request('email')
]);
return redirect()->back()->with('message', 'ok');
}
route
Route::post('/subscribe/save', [AppHttpControllersmainIndexController::class, 'subscribe'])->name('subscribe.save');
docker logs -f --details php / (Logs)
172.22.0.6 - 09/Jan/2021:17:58:27 +0000 "POST /index.php" 302 // Everything is fine
172.22.0.6 - 09/Jan/2021:17:58:28 +0000 "GET /index.php" 200
172.22.0.6 - 09/Jan/2021:17:58:29 +0000 "GET /index.php" 200
172.22.0.6 - 09/Jan/2021:17:58:32 +0000 "POST /index.php" 302 // Everything is fine
172.22.0.6 - 09/Jan/2021:17:58:33 +0000 "GET /index.php" 200
172.22.0.6 - 09/Jan/2021:17:58:34 +0000 "GET /index.php" 200
172.22.0.6 - 09/Jan/2021:17:58:39 +0000 "POST /index.php" 200 // Return code 200, problem!!!
172.22.0.6 - 09/Jan/2021:17:58:39 +0000 "GET /index.php" 200
172.22.0.6 - 09/Jan/2021:17:58:40 +0000 "GET /index.php" 200
172.22.0.6 - 09/Jan/2021:17:58:48 +0000 "POST /index.php" 302 // Everything is fine
172.22.0.6 - 09/Jan/2021:17:58:48 +0000 "GET /index.php" 200
172.22.0.6 - 09/Jan/2021:17:58:49 +0000 "GET /index.php" 200
question from:
https://stackoverflow.com/questions/65646475/post-requests-sometimes-return-code-302-and-sometimes-code-200 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…