【问题标题】:Postman get CSRF error when execute my request邮递员在执行我的请求时收到 CSRF 错误
【发布时间】:2019-02-10 14:01:36
【问题描述】:

我用邮递员请求下面的网址,会报错:

http://localhost:8000/api/users/register/

CSRF cookie 错误:

CSRF 失败:未设置 CSRF cookie。

邮递员中我的请求的设置:

但是如果我用 PHP 代码编写请求然后执行它就不会有这个问题:

$params = array(
    "whmcs_tblclients_id" => 1232,
    "email" => "test22@qq.com",
    "username" => "asdas_asda",
    "phone" => "15883332126",
    "password" => "123456"
);

$request = Requests::post('http://localhost:8000/api/users/register/', array(), $params);

【问题讨论】:

  • 你在使用 Postman chrome 应用吗?

标签: postman


【解决方案1】:

对于发送/接收 cookie,您应该在 Postman 中启用拦截器。 参考

http://blog.getpostman.com/2014/11/28/using-the-interceptor-to-read-and-write-cookies/

参考下方了解how to enable interceptor

How to use Postman Interceptor

除此之外,Postman Chrome 应用已被弃用,取而代之的是原生应用。所以it is better to go for native app(代替Chrome应用程序)直接支持拦截cookie,如我的回答中所述。 参考

http://blog.getpostman.com/2017/03/14/going-native/

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 2018-07-22
    • 2018-07-07
    • 2021-07-01
    • 1970-01-01
    • 2015-10-26
    • 2023-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多