Created
October 4, 2011 16:39
-
-
Save jonalter/1262126 to your computer and use it in GitHub Desktop.
Android/iOS: testing setRequestHeader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| foreach (getallheaders() as $name => $value) { | |
| print_r("$name: $value\n"); | |
| } | |
| ?> |
Author
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
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;)');