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();
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.
-
Try url encoding the querystring on that url.
Especially those < and > characters. I doubt it will like that at all.
-
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');
-
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).
-
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).
-
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).
-
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.
-
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.