上传 Laravel 6.0 项目后出现 "The GET method is not supported for this route. Supported methods: POST." 错误

After uploading Laravel 6.0 project I am getting "The GET method is not supported for this route. Supported methods: POST." error

该项目在我的本地服务器上正常运行,没有错误。但是在将项目上传到服务器后,我得到

The GET method is not supported for this route. Supported methods: POST.

错误。我用了 Laravel 6.0

Api.php:

Route::post('rates', 'ShippoController@rates');

控制器:

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/ redirects to https://canvas.safedevs.com/。当发生重定向时,POST 被转换为 GET 并且 post 数据丢失。

将请求发送到端点的 HTTPS 版本,它应该可以正常工作。

失眠 apparently has a feature to disable automatically following redirects,您可以考虑打开它。它会让您更好地了解此类问题。