我正在使用CakePHP 3.x文档开发API。为了开发此API,我使用了他们的官方文档:https : //book.cakephp.org/3.0/en/development/rest.html
当我尝试使用url http://localhost/healthcare_portal/eapi/applicants/index.json上的GET请求访问我的api时,我得到了预期的json结果
{
"applicants": [
{
"applicant_id": 1,
"name": "Manender"
},
{
"applicant_id": 2,
"name": "mayank"
}
]
}
Run Code Online (Sandbox Code Playgroud)
但是,当我在同一URL http://localhost/healthcare_portal/eapi/applicants/index.json上使用POST请求访问我的api时,出现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
}
Run Code Online (Sandbox Code Playgroud)
我尝试了其他替代方法
$input = (array) $this->request->input('json_decode', true);
Run Code Online (Sandbox Code Playgroud)
在控制器的操作中,但这是我在发布请求时收到相同的错误。如果有人遇到同样的问题,请帮助我取得突破。