如何使用 Postman 处理 Laravel $_POST 请求 [英] How to use Postman for Laravel $_POST request

查看:54
本文介绍了如何使用 Postman 处理 Laravel $_POST 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何尝试使用 Postman 向 Laravel 应用发送发布请求?

How can I try sending a post request to a Laravel app with Postman?

通常 Laravel 有一个 csrf_token,我们必须通过 POST/PUT 请求传递它.如何在 Postman 中获取和发送此值?是否有可能不关闭 CSRF 保护?

Normally Laravel has a csrf_token that we have to pass with a POST/PUT request. How can I get and send this value in Postman? Is it even possible without turning off the CSRF protection?

推荐答案

啊等等,我看错了这个问题.你想在不关闭 CSRF 保护的情况下这样做吗?就像 Bharat Geleda 说的:你可以制作一个只返回令牌的路由,然后手动将其复制到邮递员的 _token 字段中.

但我建议您从 CSRF 保护中排除您的 api 调用,如下所示,然后添加某种 API 身份验证.

But I would recommend excluding your api calls from the CSRF protection like below, and addin some sort of API authentication later.

你运行的是哪个版本的 laravel?

自 5.2 起,CSRF 令牌仅在带有 web 中间件的路由上才需要.因此,使用 web 中间件将您的 api 路由放在组外.

Since 5.2 the CSRF token is only required on routes with web middleware. So put your api routes outside the group with web middleware.

请参阅默认路由文件";文档中的标题以获取更多信息.

See the "The Default Routes File" heading in the documentation for more info.

您可以像这样在 VerifyCsrfToken 中间件中排除不应具有 CSRF 保护的路由:

You can exclude routes which should not have CSRF protection in the VerifyCsrfToken middleware like this:

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'api/*',
    ];
}

请参阅从 CSRF 保护中排除 URI";标题文档了解更多信息.

See the "Excluding URIs From CSRF Protection" heading documentation for more info.

这篇关于如何使用 Postman 处理 Laravel $_POST 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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