Skip to content

Instantly share code, notes, and snippets.

@jonalter
Created October 4, 2011 16:39
Show Gist options
  • Select an option

  • Save jonalter/1262126 to your computer and use it in GitHub Desktop.

Select an option

Save jonalter/1262126 to your computer and use it in GitHub Desktop.
Android/iOS: testing setRequestHeader
var win = Ti.UI.createWindow({
backgroundColor : 'white',
fullscreen : true
});
var button = Ti.UI.createButton({
title : 'test',
height : 60,
width : 200
});
win.add(button);
button.addEventListener('click', function(e) {
var xhr = Titanium.Network.createHTTPClient();
xhr.open('GET', 'http://____________/~jalter/test/index.php');
xhr.onerror = function(e) {
alert(e.error);
Ti.API.info('error: '+e.error);
};
xhr.setTimeout(200000);
xhr.onload = function(e) {
Ti.UI.createAlertDialog({
title : 'Success',
message : this.responseText
}).show();
Ti.API.info('onload: '+this.responseText);
};
xhr.onsendstream = function(e) {
Ti.API.info(e);
};
xhr.setRequestHeader('Content-Type','application/json');
xhr.setRequestHeader('User-Agent', 'Appcelerator......');
xhr.setRequestHeader('Accept-Encoding', 'gzip');
xhr.send();
});
win.open();
<?php
foreach (getallheaders() as $name => $value) {
print_r("$name: $value\n");
}
?>
@jonalter

Copy link
Copy Markdown
Author

Fixed the issue of Android failing when iOS was successful:

xhr.setRequestHeader('User-Agent','Appcelerator Titanium/1.8.0.v20110928105812 (iPhone Simulator/4.3.2; iPhone OS; en_US;)');

@eliransu

Copy link
Copy Markdown

Hi!
I have similar issue with my XHR request,
the IOS platform works well while Android fails when trying to set request header (customs)
do you know how can I fix this issue? thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment