[TIMOB-13031] Android: Allow HTTPClient.setRequestHeader() to be called after open()
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-03-20T22:56:46.000+0000 |
Affected Version/s | Release 3.0.2 |
Fix Version/s | Release 3.1.0, 2013 Sprint 06 API, 2013 Sprint 06 |
Components | Android |
Labels | android, exalture, mobilesdk, qe-devCheck, titanium |
Reporter | Ashish Nigam |
Assignee | Sunila |
Created | 2013-03-12T06:50:31.000+0000 |
Updated | 2013-04-01T23:42:51.000+0000 |
Description
Using HTTP client with Titanium produces different behavior.
Titanium.UI.setBackgroundColor('#000');
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
title:'Window 1',
backgroundColor:'#000'
});
var videoID = 'AO2GwKAfEqY';
vdrld = function(a, b) {// We do not get the video-id nor do we get any url; that is, we extract the ID from the image-url.
vdldr = Ti.Network.createHTTPClient();
vdldr.onload = function() {
var x, y;
Ti.API.error("################# onLoad ## ###################" + " "+ this.responseText);
x = decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(this.responseText.substring(4, this.responseText.length)))));
Ti.API.debug('vdrld: Resulting JSON was: ' + JSON.stringify(x));
y = JSON.parse(x).content.video["fmt_stream_map"][0].url;
//Ti.API.error(y);
alert(y);
//Ti.API.error(x);
alert(x);
if (y === undefined) {
Ti.API.error("vdrld: Found no fmt_stream_map in the returned JSON!!!");
return;
}
return b(y);
};
vdldr.setRequestHeader("Referer", "http://www.youtube.com/watch?v=" + a);
vdldr.setRequestHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14");
vdldr.open("GET", "http://m.youtube.com/watch?ajax=1&feature=related&layout=mobile&tsp=1&&v=" + a);
vdldr.send()
};
setTimeout(function() {
vdrld(videoID, function() {
Ti.API.debug('The resulting URL from vdrld was: ' + arguments[0]);
var videoPlayerParms = {
fullscreen: false,
top: 5,
width: 320,
height: 240,
borderColor: '#aaa',
autoplay: true,
mediaControlStyle: Titanium.Media.VIDEO_CONTROL_EMBEDDED,
scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
url: arguments[0],
};
var videoPlayer = Ti.Media.createVideoPlayer(videoPlayerParms);
win1.add(videoPlayer);
});
}, 5000);
win1.open();
*Above is working in iOS but giving error in android*
*Error Message: setRequest Header can only be called before invoking send*
it seems like behavior is not similar in iOS and Android, as i change the order of setRequestHeader method and open method then it works on both but if i try the same code then it does not show error in iOS but in Android it produces the error message mentioned above.
Here is the patch to fix this:
https://github.com/appcelerator/titanium_mobile/pull/3962
Verified fix with mobile sdk-3.1.0.v20130401102449 Titanium Studio, build: 3.1.0.201304010847 Device: HTC Amaze, Android 4.0.3 There was this in the logs:
However, since the issue was doing setRequestHeader, and that appears to work, this worked, I guess.
Did not complain about request headers.