【问题标题】:Making a HTTP-GET Request with Titanium.Network.createHTTPClient()使用 Titanium.Network.createHTTPClient() 发出 HTTP-GET 请求
【发布时间】:2012-06-21 16:26:19
【问题描述】:

我正在使用 Titanium Studio,我必须向 Couchdb 发出 HTTP 获取请求。这是我的代码:

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

操作进入超时..

【问题讨论】:

    标签: httpwebrequest timeout titanium


    【解决方案1】:

    代码运行良好。我用不同的 URL 对其进行了测试。 首先在 Web 浏览器中检查 URL 以查看加载所需的时间,然后增加超时值。 如果能正常使用模拟器的浏览器打开URL,你可能会发现是IP问题

    【讨论】:

      【解决方案2】:

      是couchdb的ip问题; couchdb 服务器监听 127.0.0.1。

      【讨论】:

        猜你喜欢
        • 2014-06-01
        • 2014-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-05
        • 1970-01-01
        • 1970-01-01
        • 2021-09-07
        相关资源
        最近更新 更多