【问题标题】:CSRF token is invalid when calling rest post api from php Client从php客户端调用rest post api时CSRF令牌无效
【发布时间】:2013-10-13 10:43:39
【问题描述】:

我在 Symfony 中创建了一个 rest api。它使用表单为客户端发送数据。 我在 setDefaultOptions 中使用了 'csrf_protection' => false,但仍然出现错误

CSRF 令牌无效。请尝试重新提交表单

【问题讨论】:

    标签: symfony fosrestbundle


    【解决方案1】:

    您是否通过NelmioApiDocBundle sanbox 测试了您的 api,或者您从前端的表单发送数据?您确定您没有将 csrf_protection 请求参数发送到您的 api 吗?

    【讨论】:

    • 我正在使用 curl 从 php 调用 api,并且 100% 确定没有发送 csrf_protection。这是客户端的示例代码 $curl_post_data = json_encode($curl_post_data); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); $curl_response = curl_exec($curl);
    猜你喜欢
    • 2015-01-26
    • 2017-04-20
    • 1970-01-01
    • 2022-11-25
    • 2020-07-12
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    相关资源
    最近更新 更多