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


