[TIMOB-2496] Android: Titanium.Network.HTTPClient.onload fired with a delay!
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2011-04-15T03:21:19.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.6.0 M01 |
Components | Android |
Labels | android, defect, httpclient, release-1.6.0 |
Reporter | Farsad |
Assignee | Don Thorp |
Created | 2011-04-15T03:21:17.000+0000 |
Updated | 2017-03-02T19:28:34.000+0000 |
Description
Titanium.Network.HTTPClient.onload fired with a delay! We tested
it with the on the Iphone and some android phones. It hasn't this
problem on the Iphone(Iphone fire it on 2 seconds). But on my
Samsung Galaxy S With android 2.2 on wifi it takes 10 to 16
seconds. On a HTC Wildfire with wifi or 3G network it takes between
3 to 5 minutes and sometimes not fired or takes longer! This issue
reported on a HTC Desire too. It seems this problem is on first run
of the app or when we clear cache and data of the app.
Also I found a same reported problems on the developer center:
http://developer.appcelerator.com/question/881/titaniumnetworkhttpclientsettimeout-blocks-opensend">
http://developer.appcelerator.com/question/881/titaniumnetworkhttpc...
I tested it by Titanium SDK 1.4.1 and 1.5 and I'm sure that the
server answer to this requests quickly (We use google servers with
the appengine) and that codes work fine on the Iphone.
We use this codes:
var SessionID = '';
Ti.App.addEventListener('nAjax', function(e)
{
var xhr = Ti.Network.createHTTPClient();
xhr.onerror = function(r) {
trace('nAjax.onerror('+e.error+'): ' + r.error);
if (e.error) {
Ti.App.fireEvent(e.error,{error:r.error, status:xhr.status});
}
if (e.complete) {
Ti.App.fireEvent(e.complete,{status:xhr.status});
}
};
xhr.onreadystatechange = function() {
trace('nAjax.onreadystatechange('+e.success+') xhr.readyState: ' + xhr.readyState);
}
xhr.onload = function() {
trace('nAjax.onload('+e.success+') xhr.status: ' + xhr.status);
if (e.success) {
cookie = xhr.getResponseHeader('Set-Cookie');
if (cookie){
if (cookie.indexOf('sessionid') > -1) {SessionID = cookie.substring(cookie.indexOf('sessionid')+10, cookie.indexOf(';'));}
}
Ti.App.fireEvent(e.success,{response:this.responseText, status:xhr.status});
}
if (e.complete) {
Ti.App.fireEvent(e.complete,{status:xhr.status});
}
};
xhr.setTimeout(30000);
xhr.open(e.method, e.url, false);
if (e.username){
Ti.API.info('xhr.setRequestHeader');
xhr.setRequestHeader('Authorization','Basic ' + Ti.Utils.base64encode(e.username+':'+e.password));
}
if (Titanium.Platform.osname == 'android'){
if (SessionID.length > 0) {xhr.setRequestHeader('Cookie',('sessionid=' + SessionID + ';'));}
}
//send the data
xhr.send(e.data);
trace('nAjax.send');
});
Attachments
File | Date | Size |
---|---|---|
app.js | 2011-04-15T03:21:17.000+0000 | 1158 |