问题
The project is working on my local server without error. But after uploading the project to the server I am getting
The GET method is not supported for this route. Supported methods: POST.
error. I used Laravel 6.0
Api.php:
Route::post('rates', 'ShippoController@rates');
Controller:
public function rates(Request $request){
$validatedData = $request->validate([
'email' => 'required|email',
'name' => 'required',
'token' => 'required',
]);
try{
$carts = Cart::whereToken($request->token)->get();
if (count($carts) == 0){
return response()->json([
'status' => 0,
'message' => 'Invalid cart token.',
], Response::HTTP_NOT_IMPLEMENTED);
}
...
return response()->json([
'status' => 1,
'data' => $data,
], Response::HTTP_OK);
}
catch (\Exception $e){
return response()->json([
'status' => 0,
'message' => $e->getMessage()
], Response::HTTP_BAD_GATEWAY);
}
}
回答1:
Your issue is that http://canvas.safedevs.com/ redirects to https://canvas.safedevs.com/. When a redirect occurs, the POST is converted to a GET and the post data lost.
Send the request to the HTTPS version of the endpoint and it should work fine.
Insomnia apparently has a feature to disable automatically following redirects, which you might consider turning on. It'll give you better visibility on issues like this.
来源:https://stackoverflow.com/questions/59430945/after-uploading-laravel-6-0-project-i-am-getting-the-get-method-is-not-supporte