从邮递员到 Laravel 的 POST 请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46012380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
POST request from Postman to Laravel
提问by Irini Koutaki
I am trying to send a post request to a Laravel project using Postman, but I get a "419 unknown status" response
我正在尝试使用 Postman 向 Laravel 项目发送发布请求,但收到“419 未知状态”响应
routes\web.php:
路线\ web.php:
Route::post('/myaction', 'MymodelController@myaction');
app\Http\Controllers\MymodelController.php:
应用\Http\Controllers\MymodelController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Mymodel;
class MymodelController extends Controller
{
function myaction()
{
return redirect('/');
}
}
Why does this happen?
为什么会发生这种情况?
The same error appears independently of the content of myaction()
出现相同的错误与内容无关 myaction()
回答by Niklesh Raut
As you are requesting api you should write your route in api.php
instead web.php
正如您所要求的API,你应该写你的路线api.php
,而不是web.php
web.php
require _token
the csrf field
web.php
需要_token
csrf 字段
回答by Antoine
回答by Nebojsa Zlatanovic
Do you have defined route for redirect('/'); in web.php ?
你有没有为redirect('/')定义路由?在 web.php 中?