Flex Quick Tip: UrlRequest Basic Auth

I am building a mobile app [will release soon] and Basic auth is required but all the normal approaches were failing on my devices until I started looking through the available UrlRequest properties and wound up finding a gem.

URLRequestDefaults.setLoginCredentialsForHost(host, username, password);

Yes, I’m serious. No more Base64 encoding, appending text, etc to authenticate a UrlRequest. Know this is only for AIR 1.0+ but that means it works for mobile. :-)

There isn’t anything special required. Just call the method with the appropriate details [host means domain name not protocol (http, https, ...), etc]. Peep the docs and enjoy!

  • Aj

    Looks useful. By basic auth do you mean basic HTTP authentication? Also does the authentication happens at every request or uses some sort of cookie?

    • http://www.johncblandii.com johncblandii

      Yes, HTTP auth.

      Thx.