【问题标题】:Laravel post request not working with postmanLaravel 发布请求无法与邮递员一起使用
【发布时间】:2019-10-01 23:36:42
【问题描述】:

我是 laravel 的新手,我遇到的问题是 post 请求无法与邮递员一起使用。我花了一整天的时间解决这个错误,但没有任何效果。也许我在某个地方犯了一个错误。您的帮助将不胜感激。

我也尝试过禁用 Kernel.php 中的以下代码

// \App\Http\Middleware\VerifyCsrfToken::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,

api.php

Route::post('country', 'Country\CountryController@countrySave');

控制器.php

 public function countrySave(Request $request){

    $country = CountryModel::create($request->all());
    return response()->json($country, 200);
}

web.php

Route::get('/', function () {
return view('welcome');
});

以下是错误

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: The POST method is not supported for this route. Supported methods: GET, HEAD. in file C:\xampp\htdocs\laravel_tutorial\blog\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php on line 256

【问题讨论】:

  • 您是否在 POSTMAN 中设置了必要的标头?
  • 奇怪,在我的情况下,我只是注释掉 CSRF 并且一切正常

标签: php laravel-5 postman


【解决方案1】:

“api.php”中的路由仅在 url 格式为“yoursite.com/api/yourRoute”时使用。见this answer to another question

Laravel 正在“web.php”中寻找一个 POST 路由,你只有一个 GET 路由。您应该查看修改 URL 以告诉 Laravel 您想要“api.php”路由。

【讨论】:

  • 我使用了正确的根目录和格式。其次,我发布并获取具有不同方法名称的路线。让路线正常工作。问题在于发布路线。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-11
  • 2021-03-24
  • 1970-01-01
  • 2021-11-07
  • 2018-07-16
  • 1970-01-01
  • 2021-07-24
相关资源
最近更新 更多