太奇怪了,我使用 postman 在 localhost:9000 上测试我的应用程序 Controller 方法,对于我的 GET api 方法,我没有问题访问和获取响应,但对于 POST api 方法,我得到:
play.filters.CSRF - [CSRF] Check failed because no token found in headers
没见过这个消息...
我有最简单的 Controller :
def invoiceQA(): Action[JsValue] = Action.async(parse.json) { request =>
Future{Ok(Json.toJson("""{"message": "got your json"}"""))}
}
我的路线:
POST /update controllers.MyController.update
在 postman 中,我收到了 403 被禁止的消息。
postman 地址:
http://localhost:9000/update
有人知道这是为什么吗..?
最佳答案
如果你看 Play ScalaCsrf Docs ,配置CSRF过滤器并检查是否给定任何条件:
- The request method is not GET, HEAD or OPTIONS.
- The request has one or more Cookie or Authorization headers.
- The CORS filter is not configured to trust the request’s origin.
如果你根本不需要 CSRF 保护,你可以通过添加以下配置来禁用过滤器(更多信息在 Play Filters Docs 中:
play.filters.disabled+=play.filters.csrf.CSRFFilter
关于scala - 无法使用 postman 执行本地主机 POST 调用( Play Framework 2.6),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45006521/