2014-04-17 171 views
1

我试图向Titanium Studio中的Coutch数据库发出请求。 我试过了代码下面,但我得到错误:无法检索数据。 如果我尝试与前http://www.appcelerator.com,我可以得到的数据。 如果我使用coutch db url http://127.0.0.1:5984,我无法获得任何数据+错误。 林想知道如果我可能应该使用另一个网址?HTTP-GET请求与Titanium.Network.createHTTPClient()coutchdb?

var url = "http://www.appcelerator.com"; 
var client = Ti.Network.createHTTPClient({ 
onload : function(e) { 
    Ti.API.info("Received text: " + this.responseText); 
    alert('success' + this.responseText); 
}, 
onerror : function(e) { 
    Ti.API.debug(e.error); 
    alert('error'); 
}, 
timeout : 5000 
}); 
client.open("GET", url); 
client.send(); 

回答

-1

如果这个127.0.0.1是你的本地地址,那么你应该使用locallhost。

例子:

http://localhost 
+0

传递'HTTP检索你的真实IP:// 127.0.0.1 /'或'的http://本地主机/'手段一模一样。 – daniula

0

你的CouchDB服务器在本地计算机上运行,​​你可以通过127.0.0.1localhost访问它。

当你在iOS模拟器中运行你的代码时,你必须记住它是具有不同IP的虚拟环境。要做出正确的查询从iPhone模拟器到CouchDB的,你必须使用它可以从ifconfig命令

ifconfig | grep inet | grep -v inet6 | cut -d ' ' -f 2