Skip to content

Instantly share code, notes, and snippets.

@lele85
Created July 26, 2013 07:39
Show Gist options
  • Save lele85/6086992 to your computer and use it in GitHub Desktop.
Save lele85/6086992 to your computer and use it in GitHub Desktop.
var getAuthString = function(username, password){
return 'Basic ' +Titanium.Utils.base64encode(username+':'+password);
};
var xhr = Titanium.Network.createHTTPClient();
xhr.open("GET", "http://requestb.in/1a0zngb1");
xhr.cache = false;
xhr.enableKeepAlive = false;
xhr.timeout = 30000;
xhr.setRequestHeader("Content-type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Authorization", getAuthString("username", "password"));
xhr.onload = function(){
alert("Yeeeee! :) ");
};
xhr.onerror = function(){
alert("Buuuuuuuu! :( ")
};
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment