该项目正在我的本地服务器上运行,没有错误。但是将项目上传到服务器后我得到了
The GET method is not supported for this route. Supported methods: POST.
错误。我使用 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);
}
}
最佳答案
您的问题是 http://canvas.safedevs.com/重定向至https://canvas.safedevs.com/ 。当发生重定向时,POST 会转换为 GET,并且 post 数据会丢失。
将请求发送到端点的 HTTPS 版本,它应该可以正常工作。
失眠apparently has a feature to disable automatically following redirects ,您可以考虑打开它。它可以让您更好地了解此类问题。
关于php - 上传 Laravel 6.0 项目后,出现 "The GET method is not supported for this route. Supported methods: POST."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59430945/