【问题标题】:work around gwt same origin policy解决 gwt 同源策略
【发布时间】:2012-08-22 03:57:05
【问题描述】:

我有一个 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 服务并且没问题。

我已经阅读了很多帖子,我想我有一个 SAME ORIGIN POLICY 问题。

我尝试了很多解决方案:

  1. 运行我使用非同源策略(chrome 和 firefox)调试我的 gwt 应用程序的浏览器
  2. 在我的 gwt 配置文件中添加行
  3. 我尝试设置代理但没有成功。我该怎么办?

你能帮我解决这个问题吗?

【问题讨论】:

    标签: gwt same-origin-policy


    【解决方案1】:

    我发现目前唯一可用的方法是启动谷歌浏览器

    --disable-web-security
    

    这会禁用同源策略。

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

    FF 和 IE 似乎没有绕过 SOP 政策的有效方法(我在网上找到的任何示例都无法正常工作并尝试了至少一周!:/)

    【讨论】:

      猜你喜欢
      • 2016-05-22
      • 2012-12-30
      • 2012-03-13
      • 2015-08-19
      • 2014-11-26
      • 2017-02-01
      • 2014-08-18
      • 2016-09-18
      • 2011-01-25
      相关资源
      最近更新 更多