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

标签 php laravel api laravel-6

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

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);
    }
}

It is a screenshot while working on my local server:

It is the error after uploading to the server

最佳答案

您的问题是 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/

相关文章:

mysql - "General error: 1005 Can' t create table"Using Laravel Schema Build and Foreign Keys

android - 如何在本地高效保存 Drawables?

php - Laravel中间件获取路由参数

mysql - ELOQUENT 使用 save() 更新数据库;

xml - 有没有办法为亚马逊的产品获取 XML?

ios - Alamofire POST 错误 token - Swift

php - 从外部设备本地访问 Laravel 5 应用程序

php - 如何使用分隔列和值的数组生成查询

PHP getter / setter

php - 如何在 PHP 中多次在 SQL 查询中漫游