Laravel 419 错误通过 POSTMAN POST 请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52389565/
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
Laravel 419 error on POST request via POSTMAN
提问by JamLis
I'm trying to send a POST request via the POSTMAN application to my API which is running Laravel 5.6.
我正在尝试通过 POSTMAN 应用程序向运行 Laravel 5.6 的 API 发送 POST 请求。
My route is as follows:
我的路线如下:
Route::post('/charge','Charge@index');
and the Charge and index function simply var_dumps the post parameter:
并且 Charge 和 index 函数只是 var_dumps post 参数:
class Charge extends Controller
{
public function index()
{
var_dump($_POST);
}
}
The response I get is a 419 unknown status error. I've got no idea what the problem is.
我得到的响应是 419 未知状态错误。我不知道问题是什么。
I'm unsure what other info to include here, but please ask if anything else would be needed to help solve this issue.
我不确定此处要包含哪些其他信息,但请询问是否需要其他任何信息来帮助解决此问题。
Thanks, J
谢谢,J
回答by Gurpal singh
It may be because you are not sending your csrf token with the form data.
这可能是因为您没有将 csrf 令牌与表单数据一起发送。
In laravel it is mandatory to send the csrf token on every request.
在 laravel 中,每次请求都必须发送 csrf 令牌。
If you don't want to send then mention you method name in the app/http/middleware/verifycsrftokem.php
file.
如果您不想发送,请在app/http/middleware/verifycsrftokem.php
文件中提及您的方法名称。
回答by Infomaster
if using postman on headers add
如果在标题上使用邮递员添加
(KEY) (VALUE)
X-CSRF-TOKEN yvthwsztyeQkAPzeQ5gHgTvlyxHfsAfE
(KEY) (VALUE)
X-CSRF-TOKEN yvthwsztyeQkAPzeQ5gHgTvlyxHfsAfE
you can found VALUE by add
您可以通过添加找到 VALUE
public function index()
{
return csrf_token();
}
and send GET on your route name then you will get VALUE of csrf
并在您的路线名称上发送 GET 然后您将获得 csrf 的价值
回答by ruhul
I was making a get request from POSTMAN and facing 419 error. However, In-case if you are still wondering how to find csrf
token even when you are making a GETrequest and facing status 419. In my case I solved the problem by adding the user-agent: xxxx
token in header.
我正在从 POSTMAN 发出获取请求并面临 419 错误。但是,万一csrf
您在发出GET请求并面临状态419时仍然想知道如何找到令牌。就我而言,我通过user-agent: xxxx
在标头中添加令牌解决了这个问题。
Example:
例子:
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36