scala - 无法使用 postman 执行本地主机 POST 调用( Play Framework 2.6)

标签 scala playframework playframework-2.0 postman csrf

太奇怪了,我使用 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/

相关文章:

scala - 提交到 Spark 集群时出现 FileNotFoundException

scala - 用于嵌套集合的 zipWithIndex(没有可变状态的发布)

java - 无法通过 Phantom 连接到 Cassandra (NoHostAvailableException)

java - 无法从 javascript 获取 json 到运行中的 java

html - 玩!框架 - 创建简单的 html 链接

java - 使用 Java 或 Javascript 对社交网站进行图像处理

scala - 映射分区迭代器返回

java - @ {'/path/to/static_content' } 在 PlayFramework 中有什么意义?

java - Play Framework、Java 和 Eclipse Luna

scala - 在 Play 框架中处理异常