从Titanium getResponseData()获取空响应,其中应该有数据

时间:2018-03-28 21:03:17

标签: appcelerator appcelerator-titanium appcelerator-mobile

我试图从第三方服务器获得回复。如果我试图得到邮递员的回复。我得到一个对象数组。所以它确实有用,我确信它确实有效。但是,当我尝试在我的应用程序上执行此操作时,它将返回此空数组:

LOG:

[INFO] :   SUCCESS AddressAddressListGet
[INFO] :   Status code 200
[INFO] :   DATA response: []
[INFO] :   Text response: []
[INFO] :   Todos os HEADERS Transfer-Encoding:Identity
[INFO] :   Content-Type:text/plain; charset=utf-8
[INFO] :   Server:Microsoft-HTTPAPI/2.0
[INFO] :   Date:Wed, 28 Mar 2018 20:36:49 GMT
[INFO] :   Connected? false
[INFO] :   Type of connection GET

这是实际的代码:

var httpRequest = function(url, timeout, _headers, method, _data, onSuc, onErr) 
{
   var client = Ti.Network.createHTTPClient({
     onload: onSuc,
     onerror: onErr,
     timeout: timeout //5000
   });


  client.open(method, url);
  if (_headers.length != 0 && _headers != 0){
     for (var key in _headers) {
       client.setRequestHeader(key, _headers[key]);
        if (_data.length != 0 && _data != 0)
        {
          client.send(JSON.stringify(_data));
        } else {
          client.send();
   }
}; //END OF FUNC HTTPREQUEST()


var AddressAddressListGet = function(onSuc, onErr, accountId) {
   if(typeof(accountId) == 'undefined' || accountId == 0)
   {
        var url = urlAddressAddressListGet + "?accountId=" + accountId;
   }
   else {
       var url = urlAddressAddressListGet;
   }
   var header = {
       "Content-Type": "application/json",
       "Authorization": Ti.App.TOKEN
   };
   var _data = 0;
   httpRequest(url, TIMEOUT, header, "GET", _data, onSuc, onErr);
}; //AddressAddressListGet

这是我成功的回调函数:

var onsucAddressAddressListGet = function(e) {
  console.log('SUCCESS AddressAddressListGet');
  console.log("Status code " + this.getStatus());
  console.log("DATA response: " + this.getResponseData());
  console.log("Text response: " + this.getResponseText());
  console.log("Todos os HEADERS " + this.getAllResponseHeaders());
  console.log("Connected? " + this.getConnected());
  console.log("Type of connection " + this.getConnectionType());
};

如何解决这个问题的任何帮助或想法都会有很大的帮助:D

0 个答案:

没有答案