Project: titanium
Issue TIMOB-20219: Android: HTTPClient not working with http redirected to https
If the request url is from http redirected to https, HTTPClient downloads garbage instead. On iOS it's working fine. In the following example, http://audio.forerunner.cc/test.pdf is permanently redirected to https://audio.forerunner.cc/test.pdf Examine the downloaded file and see it's just garbage. Replace the url with https://audio.forerunner.cc/test.pdf. It will then download the file correctly. index.js {code} var opt = {url:'http://audio.forerunner.cc/test.pdf',type:'GET',file:Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory,'test.pdf')}; require('http').request(opt); {code} http.js {code} exports.request = function(opts) {	var xhr = Ti.Network.createHTTPClient();	xhr.timeout = (opts.timeout) ? opts.timeout : 5000;	xhr.enableKeepAlive = (opts.keepAlive) ? opts.keepAlive : false;	xhr.onload = function() {	if(opts.file && OS_IOS) opts.file.remoteBackup = false; var data = (opts.format === 'json') ? JSON.parse(this.responseText) : this.responseData; var rHeader = opts.rHeader ? this.getResponseHeader(opts.rHeader) : null; if((data || rHeader) && opts.callback)	opts.callback(data, rHeader);	};	if (opts.ondatastream)	xhr.ondatastream = function(e){	opts.ondatastream(e.progress);	};	xhr.onerror = function() {	if(opts.file)	opts.file.deleteFile();	if(opts.onerror)	opts.onerror();	};	xhr.open(opts.type?opts.type:'GET', encodeURI(opts.url));	if(opts.file) xhr.file = OS_ANDROID?opts.file.nativePath:opts.file; if(opts.headers) { for(var i = 0, j = opts.headers.length; i < j; i++) { xhr.setRequestHeader( opts.headers[i].name, opts.headers[i].value ); } } if(opts.data) { xhr.send(JSON.stringify(opts.data));	} else {	xhr.send(null);	} }; {code}
Story points: 5