我正在使用 CakePHP 3.x 文档开发 API。为了开发这个 API,我使用了他们的官方文档:https://book.cakephp.org/3.0/en/development/rest.html https://book.cakephp.org/3.0/en/development/rest.html
当我尝试使用 url 上的 GET 请求访问我的 api 时http://localhost/healthcare_portal/eapi/applicants/index.json http://localhost/healthcare_portal/eapi/applicants/index.json,我得到了预期的 json 结果
{
"applicants": [
{
"applicant_id": 1,
"name": "Manender"
},
{
"applicant_id": 2,
"name": "mayank"
}
]
}
但是当我使用同一 url 上的 POST 请求访问我的 api 时http://localhost/healthcare_portal/eapi/applicants/index.json http://localhost/healthcare_portal/eapi/applicants/index.json,我收到 CSRF 不匹配令牌错误。在这种情况下 API 的响应是
{
"message": "Missing CSRF token cookie",
"url": "/applicants/index.json",
"code": 403,
"file": "/opt/lampp/htdocs/healthcare_portal/eapi/vendor/cakephp/cakephp/src/Http/Middleware/CsrfProtectionMiddleware.php",
"line": 191
}
我尝试过其他替代方案作为添加
$input = (array) $this->request->input('json_decode', true);
在我的控制器的操作中,但这是我在发布请求时遇到相同的错误。如果有人遇到同样的问题,请帮助我取得突破。