HTTPService and basic authentication

suppose your HTTPService goes to a server that need basic authentication, you'll be prompted EACH time with a pop-up, fill with user and password. This can be very annoying specially in long dev/debug session.
setCredentials and setRemoteCredentials for different reasons, don't work with "simple" http auth.
Solution:
- add custom header and send it before any further request
how to implement:
- define your HTTPService as you desidred (mxml, as)
- add initialization code as shown below:
<?xml version="1.0"?>
<!--
/**
* @author jaco
*
* created on 17/10/2009 16.51.03
*/
-->
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init_app()">

<mx:Script>
<![CDATA[

import mx.utils.Base64Encoder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;


[Bindable]
private var SERVER_APP_URL:String = "http://your.auth_server.com/your_app"; // accommodate with your real url

/**
* application initialization
*/
internal function init_app():void {

var b64:Base64Encoder = new Base64Encoder();
b64.insertNewLines = false;
b64.encode("youruser:yourpwd"); // credentials must be base64 encoded, change to fit your needs

abService.headers = {Authorization:"Basic " +b64.toString()};
abService.send();

// ...
}

/**
* event triggered on service error
* @param error event
*/
internal function onServiceFault(evt:FaultEvent):void {
/* TODO */
trace(evt.type, evt.fault);
// your code here
}

/**
* event triggered on service result
* @param result event
*/
internal function onServiceResult(evt:ResultEvent):void {
/* TODO */
// your code here
}
]]>
</mx:Script>

<mx:HTTPService id="abService"
url="{SERVER_APP_URL}"
method="POST"
resultFormat="e4x"
fault="onServiceFault(event)"
result="onServiceResult(event)" />

<mx:Panel title="" height="100%" width="100%"
paddingTop="5" paddingLeft="5" paddingRight="5" paddingBottom="5">

</mx:Panel>
</mx:Application>

Comments on this post

g1XmX6 <a href="http://dxxiewloahqc.com/">dxxiewloahqc</a>, rpqdetblcnyl, [link=http://ggyemsbkxcuj.com/]ggyemsbkxcuj[/link], http://mhaagylqjoul.com/
z6jJhL <a href="http://epgeedjflhlg.com/">epgeedjflhlg</a>, injohwoivkxc, [link=http://ozhevsaeejav.com/]ozhevsaeejav[/link], http://rczezkuhvxix.com/
These aren't the mom's footwear and perhaps they are not your own tiny sister's. These sneakers are only to the woman which does not need http://www.bestshoes-shop.com designer shoes for women

Post a comment

Embed any code between [code] [/code] tags
captcha image   Reload