Titanium Tianium HTTPClient超时不起作用
我的应用程序通过以下方式与服务器通信:Titanium Tianium HTTPClient超时不起作用,titanium,Titanium,我的应用程序通过以下方式与服务器通信: var url = "http://my.server.com"; var client = Ti.Network.createHTTPClient({ onload : function(e) { Ti.API.info("Received text: " + this.responseText); alert('success'); }, onerror : function(e) {
var url = "http://my.server.com";
var client = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000
});
client.open("GET", url);
client.send();
当服务器联机时,所有工作正常,但当服务器脱机时,onerror
功能永远不会运行,即使超过5000毫秒
是钛虫吗?
我做错了什么?在我的机器上,在3.2GA钛合金SDK和iOS 7.0.3 iPhone模拟器下,您的代码运行良好 由于我无法重现问题,您可以:
- 检查您正在运行的SDK和emulator的版本,更新其中一个或两个版本可能会有所帮助
- 尝试放置标题(请参阅下面的代码)
- 您可以尝试在创建请求时分离回调函数,这样您至少可以在创建请求时出现问题或根本不调用回调函数的原因时进行调试
var url = "http://my.server.com";
var client = Ti.Network.createHTTPClient();
client.setTimeout(5000);
client.setRequestHeader("Content-Type", "application/json; charset=utf-8");
client.onerror = function(e) {
alert("Ops!");
};
client.send();
看看这些是否对您有效。我在这里提到的明确定义超时方面取得了更好的成功。=>客户端设置超时(5000);