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

时光毁灭记忆、已成空白 提交于 2021-01-27 17:55:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!