1

我正在使用 RestyGWT 与 JBoss AS7 上的远程服务通信,但出现以下错误:

OPTIONS http://localhost:8080/remoteService No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8888' is therefore not allowed access. 
VM482:81
XMLHttpRequest cannot load http://localhost:8080/remoteService No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8888' is therefore not allowed access.   

我在后端服务器中通过@OPTIONS 启用了以下标头和访问控制:

"Access-Control-Allow-Origin", "*"
"Access-Control-Allow-Methods", "POST, GET, UPDATE, DELETE, OPTIONS"
"Access-Control-Allow-Headers", "content-type,x-http-method-override"

我与服务器通信的客户端接口如下:

@Path("/remoteService")
public interface MonitorMeService extends RestService {
    @Path(value="/getBooks")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
        void getBooks(MethodCallback<List<Books>> callback);
}

谁能告诉我我错过了什么?我缺少什么 CORS 处理?

4

2 回答 2

1

我在 RestyGWT 上成功使用了 CORS,直到我碰壁试图让会话 cookie 正常工作。我在服务器上使用 Play 框架,浏览器不配合 set-cookie 标头响应 CORS 主持的交互。

我发现通过转移到服务器上的简单反向代理设置,我可以完全免除所有 CORS 指令(也不再需要使用 JSONP)。

这使一切变得更简单,cookie 现在可以正常工作。

如果您对更多详细信息感兴趣,请对此做出回应 - 我很乐意发布更多详细信息。谢谢。JR

于 2014-11-17T00:00:49.907 回答
0

Apart from the OPTION, you have to set the Access-Control-Allow-Origin header also for other methods: POST, GET, etc

[EDIT]

I've never used restyGwt, so I dont know how to configure restyGwt servlets to set headers, but I use this filter I wrote sometime ago when I want to configure CORS in my server container. It works for any server servlet (RPC, RF, JSON, etc). I suggest to use this filter instead of dealing with headers in your app.

于 2013-11-24T17:37:38.567 回答