2011-10-13 62 views
2

我在Phonegap 1.1上使用GWT 2.4(和JQueryMobile jquery.mobile-1.0rc1.min.js,但不適用於與調用相關的任何內容)發出HTTP請求時遇到問題。 0。我想要做的是在另一臺服務器上使用POST方法來接收內容並顯示它。GWT + Phonegap跨域請求無效

在桌面上它工作正常(感謝反向代理配置)。在Phonegap上,我讀到了"the cross-domain security policy does not affect PhoneGap applications. Since the html files are called by webkit with the file:// protocol, the security policy does not apply."。但是,似乎請求從未在手機上完成,因爲響應爲空,並且狀態碼爲0 - 這是我在解決桌面上的跨域問題之前所經歷的類似行爲。

我在GWT上使用常規的RequestBuilder發送我的請求。任何想法爲什麼發生這種情況? Phonegap上的所有權限都處於活動狀態。

編輯:這裏是發送請求,從中我遺漏了我的SOAP信封我的Java代碼:

RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,url); 
    rb.setHeader("SOAPAction", "assertIdentityWithSimpleAuthentication"); 
    rb.setHeader("Content-type", "application/x-www-form-urlencoded"); 

    String envelope = "etc"; //this is my soap envelope, 

    try{ 
     rb.sendRequest(envelope, new RequestCallback() { 
     public void onError(Request request, Throwable exception) { 
      requestFailed(exception); 
      } 
     public void onResponseReceived(Request request, Response response) { 
      if(response.getStatusCode() == 200){ 
       String aid = Tools.parseMessage(response.getText(),"assertionId"); //this just parses the response in order to get the string I need 
       Window.alert("Sucess: "+ aid); 
       sendAssertionID(aid); //and sends it to another function 
      } 
      else setError(response); 
      } 
     }); 
     } 
     catch (RequestException ex) { 
      requestFailed(ex); 
     }   
+0

我使用http://code.google .com/p/gwt-phonegap /對於一些應用程序,但是沒有任何與Requestbuilder有關的問題,你可以發佈你的一些代碼嗎? –

+0

感謝您的回覆,丹尼爾,我用代碼更新了我的問題。我目前沒有使用GWT-Phonegap,目前我只是在我的Phonegap項目上使用導出的GWT材質。 – Ineze

+0

對不起,我忘了問你在哪個plattform上運行:android,ios ....另一件事你只是想到你加載一個本地index.html文件? –

回答

1

檢查您的網址。您的代碼工作在我的Android設備上很好,但失敗的網址無效代碼爲0

它需要以http://或https://

+0

我的網址以http://開頭,並且是我網絡上的服務器,所以我不認爲這是問題所在。 – Ineze

+0

好的,這不完全是問題,但你的答案幫助我到達那裏:)問題是,Android系統不是,出於某種原因,識別我的服務器的名稱。在你回答之後,我記得檢查模擬器和我的終端是否可以在瀏覽器上訪問服務器,但它沒有!使用本地IP而不是URL解決了問題。非常感謝你,如果你沒有提到URL,我肯定還會被卡住! – Ineze

+0

很高興我能幫忙:) –