Basic Authentication with Titanium.Network.HTTPClient

I've been trying, over the last couple of days, to figure out how to do an HTTP request with Basic Authentication using Appcelerator Titanium.

It seemed like it should be pretty easy. Just create an HTTPClient object, pass it the username and password via setBasicCredentials(), and off you go.

But it didn't work. I got 401 - Unauthorized on every single site I tried.

Finally, after way too much research, I discovered that setBasicCredentials just doesn't work and you have to do Basic Authentication by setting the headers yourself like this:

~~~~ {.javascript name="code"} authstr = 'Basic ' +Titanium.Utils.base64encode(username+':'+password); xhr.setRequestHeader('Authorization', authstr); wzxhzdk:0