Flex HTTPService and Basic Authentication
For an internal project I created an Adobe AIR application that connects to the Basecamp API. We have been using the application since the launch of Adobe AIR. Back then I had a problem connecting to the API using the HTTPService, because the combination of Basic Authentication and the https protocol was not supported. After several unsuccessful experiments I decided to go for an approach that uses a PHP Proxy on the server that delegates the calls to the Basecamp API. However the downside of this approach is that this setup needs extra configuration and a server-side deployment.
This week I got the chance to pick it up again and I stumbled upon this forum post on the Basecamp Forum. I found this piece of code posted on Verveguy's blog. And it actually did the trick.
username:String, password:String):void
{
//add the header to request
var enc:Base64Encoder = new Base64Encoder();
enc.encode(username + ":" + password);
service.headers["Authorization"] = "Basic " + enc.toString();
}
For everybody who needs to connect a Flex application to an API that uses https in combination with Basic Authentication, here is the solution. All credits to the original blog post.


