[TIMOB-13930] Android: HttpClient calls onerror instead of onload if autoRedirect is set to false
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Release 3.1.0, Release 3.2.0 |
Fix Version/s | n/a |
Components | n/a |
Labels | parity |
Reporter | Nasif |
Assignee | Unknown |
Created | 2013-04-25T08:13:44.000+0000 |
Updated | 2018-02-28T20:03:29.000+0000 |
Description
*Problem description*
On Android, setting the property autoRedirect to false causes onerror to be called instead of onload. It works as expected on iOS.
*Actual result*
HttpClient is calling onerror instead of onload
*Expected result*
onload should be called on Android even if it is a HTTP redirect (302 or 304), since these are not errors.
*Test case*
var win = Ti.UI.createWindow({
backgroundColor : "#FFF"
});
var onload = function(e) {
alert(this.test_type + ": RETURN CODE:" + this.status);
};
var onerror = function(e) {
alert(this.test_type + ": ERROR CODE:" + this.status);
};
var xhr = Ti.Network.createHTTPClient({
onload : onload,
onerror : onerror,
test_type : "DEFAULT"
});
xhr.open('GET', 'https://support.appcelerator.com');
xhr.send();
var xhr1 = Ti.Network.createHTTPClient({
onload : onload,
onerror : onerror,
test_type : "REDIRECT OFF"
});
xhr1.open('GET', 'https://support.appcelerator.com');
xhr1.autoRedirect = false;
xhr1.send();
var xhr2 = Ti.Network.createHTTPClient({
onload : onload,
onerror : onerror,
test_type : "REDIRECT ON"
});
xhr2.open('GET', 'https://support.appcelerator.com');
xhr2.autoRedirect = true;
xhr2.send();
win.open();
Hello! In order to promote this bug into Mobile SDK, can you please provide more info? Please follow this guideline: https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report If you have a small testcase showing this, will be awesome! Best, Mauro
var onload = function(e) { Ti.API.info(this.test_type + ": RETURN CODE:" + this.status); }; var onerror = function(e) { Ti.API.info(this.test_type + ": ERROR CODE:" + this.status); }; var xhr = Ti.Network.createHTTPClient({ onload: onload, onerror: onerror, test_type: "DEFAULT" }); xhr.open('GET','https://support.appcelerator.com'); xhr.send(); var xhr1 = Ti.Network.createHTTPClient({ onload: onload, onerror: onerror, test_type: "REDIRECT OFF" }); xhr1.open('GET','https://support.appcelerator.com'); xhr1.autoRedirect = false; xhr1.send(); var xhr2 = Ti.Network.createHTTPClient({ onload: onload, onerror: onerror, test_type: "REDIRECT ON" }); xhr2.open('GET','https://support.appcelerator.com'); xhr2.autoRedirect = true; xhr2.send();
Tested and confirmed on Android 4.1.2 x86 emulator with Ti SDK 3.2 CI. Works as expected on iOS.