我已经部署在本地我的播放应用程序,并从内我的浏览器完美的作品通过访问我的localhost:9000
REST API。播放CORS不工作
不过,我从file:///C:/Users/XXX/XXX//index.html
执行jQuery脚本(见下文)时,遇到下列错误:
Failed to load resource: the server responded with a status of 403 (Forbidden)
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.
我跟着https://www.playframework.com/documentation/2.6.x/CorsFilter下的指示。
我build.sbt
:
libraryDependencies ++= Seq(
jdbc,
evolutions,
guice,
"com.h2database" % "h2" % "1.4.194",
javaJpa,
"org.hibernate" % "hibernate-core" % "5.2.5.Final",
filters
)
我application.conf
:
注:我都尝试allowedOrigins = null
& allowedOrigins = ["*"]
jQuery的脚本:
$.ajax({
'url' : 'http://localhost:9000/employee/' + user_id + '/weeklyWorkingHours',
'type' : 'GET',
'success' : function(data) {
console.log('Data: '+ JSON.stringify(data));
},
'error' : function(request,error)
{
console.log("Error: "+JSON.stringify(request));
}
});
这里是戏称:
[warn] p.f.c.CORSFilter - Invalid CORS request;Origin=Some(null);Method=GET;Access-Control-Request-Headers=None
播放规格说,'在默认情况下所有的起源是allowed'。你提到你尝试了所有的'allowedOrigins = null'&'allowedOrigins = “*”]'。您是否尝试删除它? – Bruno
感谢您的提示。不幸的是,它并没有做到这一点。 – mollwitz
我认为这个问题是在这里'产地=一些(空)'。比赛将验证此为'isValidOrigin =新的URI( “空”)。getScheme NE null'。其中返回false。你可以尝试用有效的“Origin”来完成请求吗?这是'Origin = <一些有效的url>'? – Bruno