【发布时间】:2014-03-24 09:55:50
【问题描述】:
我有一个 AngularJs 前端和一个 playframework 2 Scala 后端。查看 this 将 COR 添加到后端 - 我有两个端点:GET 和 POST
GET /api/question/:id controllers.Questions.getQuestion(id: String)
POST /api/question/:id controllers.Questions.postQuestion(id: String)
其他响应中提供的此解决方案适用于 GET,但不适用于 POST
def getQuestion(key:String) = CorsAction{
....
}
def postQuestion(key:String) = CorsAction(parse.json){
req =>
........
}
我的理解是CORsAction(扩展ActionBuilder)也可以接受bodyparser的方法,因此基本上也应该适用于POST请求。
这是我从前端点击 POST 时在浏览器控制台中看到的内容。
OPTIONS http://localhost:9000/api/question/abc123 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3001' is therefore not allowed access. angular.js:7997
XMLHttpRequest cannot load http://localhost:9000/api/question/abc123. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3001' is therefore not allowed access.
【问题讨论】:
标签: json scala post playframework-2.0 cors