Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Created July 15, 2011 17:47
Show Gist options
  • Save benbahrenburg/1085149 to your computer and use it in GitHub Desktop.
Save benbahrenburg/1085149 to your computer and use it in GitHub Desktop.
Android XHR issue
bGet.addEventListener('click', function(){
var _url = "https://my.url.goes.here";
var username='demo';
var password='badpass';
var aToken = 'Basic ' + Ti.Utils.base64encode(username + ':' + password);
var c = Titanium.Network.createHTTPClient();
c.setTimeout(10000);
c.onload = function(e)
{
Ti.API.info("ONLOAD = "+e);
Ti.API.info('this.status=' + this.status);
var results = this.responseText;
Ti.API.info('results=' + results);
};
// c.ondatastream = function(e){
// Ti.API.info('ONDATASTREAM1 - PROGRESS: ' + e.progress);
// };
c.onerror = function(e)
{
Ti.API.info('this.status=' + this.status);
Ti.API.info('c.status='+ c.status);
Ti.API.info(this.responseText);
Ti.UI.createAlertDialog({title:'XHR', message:'Error: ' + e.error}).show();
};
c.open('GET',_url);
c.setRequestHeader("Authorization", aToken);
c.send();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment