上载Laravel 6.0项目后,我得到“此路线不支持GET方法.支持的方法:POST.错误 [英] After uploading Laravel 6.0 project I am getting "The GET method is not supported for this route. Supported methods: POST." error

查看:58
本文介绍了上载Laravel 6.0项目后,我得到“此路线不支持GET方法.支持的方法:POST.错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该项目正在我的本地服务器上正常运行.但是将项目上传到服务器后,我得到了

The project is working on my local server without error. But after uploading the project to the server I am getting

此路由不支持GET方法.支持的方法:POST.

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

错误.我使用了Laravel 6.0

error. I used 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/重定向到 http s ://canvas.safedevs.com/.发生重定向时,POST会转换为GET,并且帖子数据会丢失.

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.

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

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.

这篇关于上载Laravel 6.0项目后,我得到“此路线不支持GET方法.支持的方法:POST.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆