Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Network.createHTTPClient() fails to call URL

I am using the Network.createHTTPClient() to make an external URL call. The URL is valid and works in a browser but in the Titanium mobile API it fails to even do the call to the server. Also the onload and error do not get called. Now if I change the URL to be http://www.google.com then it works.

Any help would be appreciated.

var xhr = Titanium.Network.createHTTPClient();
    //xhr.setTimeout(10000);

    xhr.onload = function() {
        Titanium.API.info('xml ' + this.responseXML + ' text ' + this.responseText);
        accountDetailsBtn.setTitle('Status:'+this.status);
    };
    xhr.error = function() {
        Titanium.API.info('error response, http status code ' + this.status);
        accountDetailsBtn.setTitle('Status:'+this.status);
    };
    Titanium.API.info('call CLTS server: ' + cltsURL);
    //xhr.setRequestHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.371.0 Safari/533.4");
    xhr.open('GET', "http://www.clia.localhost.ccia.net:8988/CLTS/webservice/accountmanagementrestv1/searchaccounts?username=name&password=pass&xml=<xml-fragment><criteria><accountId>A0003205</accountId></criteria><index>0</index><maxResultsSize>10</maxResultsSize></xml-fragment>");
    xhr.send();
— asked May 3rd 2010 by Nigel Heywood
  • createhttpclient
  • network
  • send
  • url
  • xhr
0 Comments

8 Answers

  • Hey Nigel,

    I just tried that URL and it wasn't able to resolve, 100% sure that's correct? Just wanted to double check since it's not working on my end and "http://www.clia.localhost.ccia.net" looks like it might not be right.

    — answered May 3rd 2010 by Dan Giulvezan
    permalink
    0 Comments
  • Try url encoding the querystring on that url.

    Especially those < and > characters. I doubt it will like that at all.

    — answered May 3rd 2010 by Kosso
    permalink
    0 Comments
  • So I encoded the URL and the call seems to do nothing, meaning that neither the onload or error functions are called. The URL is correct but is it a URL in our intranet. I did change the xhr.open to be a image (with https) with no special characters but it still does not work…or seems to not work (I receive no call on the server). How do I know if its working? would a request header help on a mobile device? below is a external url that should work and does work in a browser but not in Titanium.

    xhr.open('GET', 'https://www.clia.livestockid.ca/CLTS/public/division/CCIA/en/splash_logo.jpg');
    
    — answered May 4th 2010 by Nigel Heywood
    permalink
    0 Comments
  • Hi All,

    I am still stuck on this issue. This is a key part of our mobile application so if we cannot talk to our server's web services then we cannot move forward.

    Any help? I assume that I am not the first to have this issue…

    Is there anyway to see if the sending is even working for this URL (yes the URL is correct and works from a browser).

    — answered May 5th 2010 by Nigel Heywood
    permalink
    0 Comments
  • Hi All,

    I am still stuck on this issue. This is a key part of our mobile application so if we cannot talk to our server's web services then we cannot move forward.

    Any help? I assume that I am not the first to have this issue…

    Is there anyway to see if the sending is even working for this URL (yes the URL is correct and works from a browser).

    — answered May 5th 2010 by Nigel Heywood
    permalink
    0 Comments
  • Hi All,

    I am still stuck on this issue. This is a key part of our mobile application so if we cannot talk to our server's web services then we cannot move forward.

    Any help? I assume that I am not the first to have this issue…

    Is there anyway to see if the sending is even working for this URL (yes the URL is correct and works from a browser).

    — answered May 5th 2010 by Nigel Heywood
    permalink
    0 Comments
  • Hey Nigel,

    The image URL works but you have to use this.responseData in this case to see what's returned. Here's a really basic example using your URL that takes what's returned and displays it in an imageView:

    var xhr = Titanium.Network.createHTTPClient();
    var win1 = Ti.UI.createWindow();
    var image1 = Ti.UI.createImageView();
    win1.add(image1);
    win1.open();
    xhr.onload = function() {
        image1.image = this.responseData;
    };
    xhr.open('GET', 'https://www.clia.livestockid.ca/CLTS/public/division/CCIA/en/splash_logo.jpg');
    xhr.send();
    

    Not sure if using this.responseData will help with your larger problem, hopefully it will.

    — answered May 5th 2010 by Dan Giulvezan
    permalink
    0 Comments
  • I found the problem!

    So I started thinking about the local URL and found that we use the Windows Host file to resolve the www.clia.localhost.ccia.net and so I replaced the host with my specific IP and then it worked. I cannot believe that I was stuck on this stupid solution, sorry.

    Thanks for the help.

    — answered May 6th 2010 by Xin Zhang
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.