如何为 RESTEasy 预检请求设置 Access-Control-Allow-Origin?
how to set Access-Control-Allow-Origin for RESTEasy preflight request?
服务器端代码(我的 RESTEasy 服务器是 http://myServer 上的 运行):
预检请求处理程序:
@PermitAll
@OPTIONS
@Path("/uploadFile")
public Response preFlightUploadFile() throws Exception {
logger.info("preFlightUploadFile");
return Response.ok()
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
.header("Access-Control-Allow-Headers", "accept, Cache-Control, content-type, x-requested-with")
.build();
}
预检响应:
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Origin: http://myServer
Content-Length: 0
Date: Wed, 12 Oct 2016 16:16:16 GMT
为什么回复被覆盖了?
如有任何帮助,我将不胜感激。
显然,myServer 中有一些过滤器正在覆盖我的设置..
我更改了它并且我的代码有效..
服务器端代码(我的 RESTEasy 服务器是 http://myServer 上的 运行):
预检请求处理程序:
@PermitAll
@OPTIONS
@Path("/uploadFile")
public Response preFlightUploadFile() throws Exception {
logger.info("preFlightUploadFile");
return Response.ok()
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
.header("Access-Control-Allow-Headers", "accept, Cache-Control, content-type, x-requested-with")
.build();
}
预检响应:
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Origin: http://myServer
Content-Length: 0
Date: Wed, 12 Oct 2016 16:16:16 GMT
为什么回复被覆盖了?
如有任何帮助,我将不胜感激。
显然,myServer 中有一些过滤器正在覆盖我的设置.. 我更改了它并且我的代码有效..