GWT + Phonegap跨域请求无效

时间:2011-10-13 11:19:30

标签: gwt cordova xmlhttprequest cross-domain

我在Phonegap 1.1.0上使用GWT 2.4(和JQueryMobile jquery.mobile-1.0rc1.min.js,但不是与调用相关的任何内容)进行HTTP请求时遇到问题。我想要做的是在另一台服务器上使用POST方法,以便接收内容并显示它。

在桌面上它运行正常(感谢反向代理配置)。在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上的所有权限都是有效的。

编辑:这是我发送请求的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);
      }         

1 个答案:

答案 0 :(得分:1)

检查您的网址。您的代码在我的Android设备上运行正常,但是代码为0的代码无效。

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

开头
相关问题