解决gwt同源政策

时间:2012-08-27 16:22:28

标签: gwt same-origin-policy

我有一个gwt应用程序,我在标准gwt端口8888上调试,与在端口8080上运行的JAX-RS / Jersey / Glassfish服务通信

这是gwt代码:

StringBuffer postData = new StringBuffer();

postData.append(URL.encode("username")).append("=").append(URL.encode(user));
postData.append("&");
postData.append(URL.encode("password")).append("=").append(URL.encode(password));

RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, "http://localhost:8888/gestdoc/resources/data/login");
builder.setHeader("Content-type", "application/x-www-form-urlencoded");
try {
    builder.sendRequest(postData.toString(), new RequestCallback() {

          public void onResponseReceived(Request request, Response response) 
          {
              String responseText = response.getText();
              String headers= response.getHeadersAsString();
              String statusText= response.getStatusText();
              int statusCode= response.getStatusCode();
              String toString= response.toString();


              System.out.println("responseText: "+responseText);
              System.out.println("headers: "+headers);
              System.out.println("statusTest: "+statusText);
              System.out.println("statusCode: "+statusCode);
              System.out.println("toString: "+toString);

              GestoreUtenze.this.cddoc.loginResponse(true);
          }


          public void onError(Request request, Throwable exception) {
             // exception handling
          }
        });
} catch (RequestException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

这是输出:

responseText: 
headers: 
statusTest: 
statusCode: 0
toString: com.google.gwt.http.client.Request$1@6c1a82

我有一个java批处理客户端,我已经测试了我的Jersey服务并且没问题。

我看了很多帖子,我想我有一个相同的原因政策问题。

我尝试了很多解决方案:

  1. 运行我使用非同源策略(chrome和firefox)调试我的gwt应用程序的浏览器
  2. 在我的gwt配置文件中添加行
  3. 我试图设置代理但没有成功。我该怎么办?
  4. 你能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

我发现这种票价的唯一可行方式是使用

启动Google Chrome
--disable-web-security

这会禁用同源策略。

按[Strg + SHift +右键单击] - >可以在Win 7中执行此操作属性并向目标属性添加--disable-web-security。但是,您应该只在调试时使用此属性!

FF和IE似乎没有办法绕过SOP政策(无法获得我在网上找到的任何一个例子,至少工作了一周!:/)

相关问题