上传 Laravel 6.0 项目后,我得到“此路由不支持 GET 方法.支持的方法:POST."错误

编程入门 行业动态 更新时间:2024-10-25 06:31:36
本文介绍了上传 Laravel 6.0 项目后,我得到“此路由不支持 GET 方法.支持的方法:POST."错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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/ 重定向到 https://canvas.safedevs/.发生重定向时,POST 将转换为 GET,并且发布数据丢失.

Your issue is that http://canvas.safedevs/ redirects to https://canvas.safedevs/. 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 显然具有禁用自动跟随重定向的功能,您可能会考虑打开.它会让您更好地了解此类问题.

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 06:29:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/932785.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   不支持   路由   错误   上传

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!