我有一个java play框架2.4.x Web应用程序,提供JSON/HTTP API.当我运行我的前端HTML/JS file:///Users/nize/tmp/index.html在http://localhost:9000chrome show上调用API时
XMLHttpRequest cannot load http://localhost:9000.
No 'Access-Control-Allow-Origin' header is present
on the requested resource. Origin 'null' is therefore
not allowed access. The response had HTTP status code 403.
Run Code Online (Sandbox Code Playgroud)
我已根据Play Framework 2.4.x CORS文档中的说明配置了Web应用程序:
build.sbtFilters.java到项目的根目录(也尝试过/app)添加以下节到 application.conf
play.filters.cors {allowedOrigins = ["*"," http:// localhost "] #allowedHttpMethods = ["GET","POST"] #allowedHttpHeaders = ["Accept"] #preflightMaxAge = 3 days}
我错过了什么?
编辑: 症状看起来与其他非常相似的stackoverflow帖子相同或类似.通过重新配置计算机上安装的Cisco AnyConnect VPN解决了该问题.但是,我没有安装该软件.