【问题标题】:HTTP-GET Request with Titanium.Network.createHTTPClient() to coutchdb?带有 Titanium.Network.createHTTPClient() 的 HTTP-GET 请求到 coutchdb?
【发布时间】:2014-06-01 17:53:52
【问题描述】:

我试图在 Titanium Studio 的 Coutch db 上向我的数据库发出请求。 我尝试了下面的代码,但出现错误:无法检索数据。 如果我尝试使用 ex url http://www.appcelerator.com, 我可以获得数据。 如果我使用 coutch db url http://127.0.0.1:5984,我无法获得任何数据 + 错误。 我想知道我是否应该使用另一个网址?

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

【问题讨论】:

    标签: json titanium couchdb titanium-mobile getjson


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

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

      例子:

      http://localhost
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-03
        相关资源
        最近更新 更多