2012-08-27 113 views
2

我有一個GWT應用程序,我的標準GWT 8888端口與端口8080工作圍繞GWT同源策略

運行的JAX-RS /新澤西/ Glassfish的服務comunicate上調試這是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: [email protected] 

我有一個java批量客戶機與我過我的球衣服務,都OK。

我看了很多文章,我想我有一個相同的原始政策問題。

我已經嘗試了許多解決方案:

  1. 運行瀏覽器在那裏我調試我與非同源策略(Chrome和Firefox)GWT應用
  2. 添加的行中我的GWT配置文件
  3. 我試圖建立一個沒有成功的代理。我能怎麼做?

請問您能幫我解決這個問題嗎?

回答

1

唯一可用的辦法,我發現這樣的票價已開始谷歌瀏覽器與

--disable-web-security 

這將禁用同源策略。

您可以在Win 7中通過按[Strg + SHift +右鍵單擊] - >屬性並將--disable-web-security添加到目標屬性中執行此操作。但是,您應該只在調試時使用該屬性!

FF和IE似乎沒有一種繞過SOP策略的工作方式(無法獲得我在網上找到的任何示例,無法在工作中嘗試並至少嘗試一週!):