Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13930] Android: HttpClient calls onerror instead of onload if autoRedirect is set to false

GitHub Issuen/a
TypeBug
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.1.0, Release 3.2.0
Fix Version/sn/a
Componentsn/a
Labelsparity
ReporterNasif
AssigneeUnknown
Created2013-04-25T08:13:44.000+0000
Updated2018-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();

Comments

  1. Mauro Parra-Miranda 2013-04-26

    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
  2. Nasif 2013-04-27

    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();
  3. Daniel Sefton 2013-05-20

    Tested and confirmed on Android 4.1.2 x86 emulator with Ti SDK 3.2 CI. Works as expected on iOS.

JSON Source