Ineze
Ineze

Reputation: 389

GWT + Phonegap Cross domain Requests not working

I'm having trouble with making HTTP Requests using GWT 2.4 (and JQueryMobile jquery.mobile-1.0rc1.min.js, but not for anything related with the calls) on Phonegap 1.1.0. What I want to do is to use the POST method on another server in order to receive content and display it.

On the desktop it's working fine (thanks to a reverse proxy configuration). On Phonegap, I read that "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.". However, it seems that the request is never made on the phone, as the response is empty and the status code 0 - a similar behavior that I experienced before I solved the cross domain issue on the desktop.

I'm using the regular RequestBuilder on GWT to send my requests. Any ideas on why this is happening? All the permissions on Phonegap are active.

edit: Here is my Java code that sends the request, from which I omitted my soap envelope:

    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);
      }         

Upvotes: 2

Views: 1174

Answers (1)

Daniel Kurka
Daniel Kurka

Reputation: 7985

Check your url. Your code works fine on my android devices, but fails with an invalid url with code 0.

It needs to start with http:// or https://

Upvotes: 1

Related Questions