如何处理可以'无法在Titanium应用程序上访问主机

How handle can't reach host on Titanium appcellerator

本文关键字:Titanium 应用 应用程序 主机 访问 程序上 何处理 处理      更新时间:2024-02-20

我使用此代码示例在HTTP服务器上发送GET请求。

var url = "http://myserver.com/resource.html";
     var client = Ti.Network.createHTTPClient({
         // function called when the response data is available
         onload : function(e) {
             alert('success');
         },
         // function called when an error occurs, including a timeout
         onerror : function(e) {
             Ti.API.debug(e.error);
             alert('error');
         },
         timeout : 5000  // in milliseconds
     });
     // Prepare the connection.
     client.open("GET", url);
     // Send the request.
     client.send();

如果请求具有成功响应,则会正确调用onload。如果请求有一个错误响应,如404 Not Found,则会正确调用oneror。但如果主机是不可检查的,则调用onload和oneror。我能为处理主机不可检测做些什么?

我注意到这种行为只在浏览器上进行。在Android设备上,所有操作都很好