jump to navigation

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

Posted by Mayank in actionscript, flex.
Tags: , , , ,
trackback

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!!!

Comments»

1. Anirudh Sasikumar - July 14, 2008

Hi Mayank,

The following link to an Adobe technote might turn out to be useful since there’s been a lot of questions revolving around the Authorization header getting blacklisted: http://www.adobe.com/go/kb403184

Regards,
Anirudh

2. Sending Authentication Headers in Flex | Psyked - February 10, 2009

[...] In Flex (with HTTP Service class): http://geekzguru.wordpress.com/2008/07/04/ howto-add-basic-authentication-header-to-httpservice/ [...]

3. Abhishek Tiwari - March 7, 2009

@Mayank, @Anirudh

The Auth header doesnt seem to work with Flash 9 and above due to the blacklisting. Is there a way around this?

Abhishek

Mayank - March 8, 2009

What is the complete version of your flash player?

4. Basic HTTP Authorisierung in Actionscript 3 | boxedfolder.com - Flex, Flash & Web - March 29, 2009

[...] Erklärungen gibt es im unten stehenden Artikel. Link zum Artikel. « vorheriger Eintrag 28. März 2009 (19:37 Uhr) – flash & flex, web nach [...]