jump to navigation

Howto: Add Basic Authentication Header to HTTPService July 4, 2008

Posted by Mayank in actionscript, flex.
Tags: , , , ,
7 comments

HTTPService in flex supports addition of headers as required. Follow the steps below to add authetication headers to your HTTPService when accessing a service protected by basic authentication.

<mx:Script>
    <![CDATA[
        import mx.utils.Base64Encoder;
        import mx.controls.Alert;
        
        private var baseUrl:String = "http://phprestsql.sourceforge.net/tutorial/user";
        private var auth:String = "p126371rw:demo";
        
        private function init():void{
            var encoder : Base64Encoder = new Base64Encoder();
            encoder.encode(auth);
            userService.headers["Authorization"] = "Basic " + encoder.toString();
            deleteUser();
        }
    ]]>
</mx:Script>
	

Enjoyyy!!!