mary
mary

Reputation: 355

Making a HTTP-GET Request with Titanium.Network.createHTTPClient()

I am working with Titanium Studio and I have to make an HTTP get request to Couchdb. This is my code:

var url ="http://192.168.0.152:5985/hello_world/00a271787f89c0ef2e10e88a0c0001f4";
var json;

var xhr = Ti.Network.createHTTPClient({
onload: function() {
Ti.API.info("Received text: " + this.responseText);
json = JSON.parse(this.responseText); 
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT:   " + this.responseText);
Ti.API.debug("ERROR:  " + e.error);
alert('There was an error retrieving the remote data. Try again.');
},
timeout:5000
});
xhr.open("GET", url);
xhr.send();

The operation go in time out..

Upvotes: 1

Views: 2330

Answers (2)

mary
mary

Reputation: 355

It is an ip problem in couchdb; couchdb server listen in 127.0.0.1.

Upvotes: 0

hini
hini

Reputation: 240

the code works fine. I tested it with a different URL. first check the URL in a web browser to see how much it takes to load, then increase the timeout value. if it works fine try opening the URL in the browser of the simulator, you may find that it's an IP problem

Upvotes: 2

Related Questions