Java Play 2.4.x中的CORS设置
我在使用play 2.4.x设置CORS时遇到了一些问题。我正在使用play存储和检索图像文件。在使用javascript访问play的纯本机test.html文件上的图像“”时,它抛出CORS安全错误 我做了以下工作: 在游戏中- Application.conf我添加的文件Java Play 2.4.x中的CORS设置,java,cors,playframework-2.4,Java,Cors,Playframework 2.4,我在使用play 2.4.x设置CORS时遇到了一些问题。我正在使用play存储和检索图像文件。在使用javascript访问play的纯本机test.html文件上的图像“”时,它抛出CORS安全错误 我做了以下工作: 在游戏中- Application.conf我添加的文件 play.filters.cors { allowedOrigins = null allowedHttpMethods = ["GET", "POST"] allowedHttpHeaders = ["Ac
play.filters.cors {
allowedOrigins = null
allowedHttpMethods = ["GET", "POST"]
allowedHttpHeaders = ["Accept"]
preflightMaxAge = 3 days
}
在Filter.java文件中(根目录中)
在build.sbt文件中
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
filters
)
我试图将图像加载到画布的html文件中的javascript代码:
$("#test").recScribble.loadImage('http://localhost:9000/assets/images/favicon.png');
我的recScribble插件具有如下loadImage函数,画布上下文为ctx
$.fn.recScribble.loadImage=function(imgSrc){ //to Load image on to the canvas; give the link as parameter
var imageObj = new Image();
imageObj.setAttribute('crossOrigin', 'anonymous');
imageObj.src =imgSrc;
imageObj.onload = function() {
canvas.width=imageObj.naturalWidth;
canvas.height=imageObj.naturalHeight;
ctx.drawImage(imageObj, 0, 0);
};
return this;
};
HTML返回CORS安全错误,其中包含以下信息
概述
Request URL:http://localhost:9000/assets/images/favicon.png
Request Method:GET
Status Code:403 Forbidden
Remote Address:[::1]:9000
响应标题
Content-Length:0
Date:Sat, 12 Dec 2015 02:35:47 GMT
请求标题
Accept:image/webp,image/*,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Host:localhost:9000
Origin:null
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36
当我从正确启用CORS的其他服务器(在Internet上)访问图像时,使用相同的HTML文件加载图像是有效的。所以我猜,javascript没有问题(但不确定)
我是新手,不知道该换哪种环境。请。救命啊
Accept:image/webp,image/*,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Host:localhost:9000
Origin:null
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36