无法通过浏览器访问Laravel中的POST路由 [英] Cannot access POST route in Laravel via browser

查看:284
本文介绍了无法通过浏览器访问Laravel中的POST路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Laravel 5.4在web.php中具有此路由

Using Laravel 5.4 have this route in web.php

Route::post('foo/bar', function () {
    return 'Hello World';
});

但是当我在浏览器中访问 http://localhost:8000/foo/bar URL时我有这个错误:

but when I visit the http://localhost:8000/foo/bar URL in browser I have this error:

RouteCollection.php第251行中的

MethodNotAllowedHttpException: RouteCollection.php在第251行 RouteCollection-> methodNotAllowed(array('POST'))在 RouteCollection.php第238行位于 RouteCollection-> getRouteForMethods(object(Request),array('POST'))在 RouteCollection.php在第176行 Router.php第533行中的RouteCollection-> match(object(Request))...

MethodNotAllowedHttpException in RouteCollection.php line 251: in RouteCollection.php line 251 at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 238 at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 176 at RouteCollection->match(object(Request)) in Router.php line 533 ...

我想通过浏览器测试POST路由方法.

I want to test a POST route method via the browser.

推荐答案

更改它

Route::post(

Route::get(

然后重试.

说明: Route::post()用于我们要发布包含一些数据的表单.

Explanation: Route::post() is used when we want to post the form with some data in it.

这篇关于无法通过浏览器访问Laravel中的POST路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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