0 Replies Latest reply on Aug 27, 2009 6:16 AM by Marc de kwant

    HTTPService basic authorization headers...

    Marc de kwant Level 1

      Hi,

       

      I am trying to programatically add the Authorization header to a HTTPService call, but apparently the flash player 9 and 10 remove this header. crossdomain.xml with

       

       

      <?xml version="1.0"?>

      <!DOCTYPE cross-domain-policy SYSTEM

      "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">

      <cross-domain-policy>

        <allow-access-from domain="*"/>

        <allow-http-request-headers-from domain="*" headers="Authorization"/>

      </cross-domain-policy>

       

       

      Does not work either.

       

      My code is as follows:

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

       

          <mx:Script>

          <![CDATA[

          import mx.controls.Alert;

          import mx.rpc.events.ResultEvent;

          import mx.rpc.events.FaultEvent;

          import mx.utils.Base64Encoder;

         

             private function addAuthHeader(serv:*, username:String,password:String):void {

                   //add the header to request

                   var encoder : Base64Encoder = new mx.utils.Base64Encoder();

                   encoder.insertNewLines = false;

                   encoder.encode(username + ":" + password);

                   var prop:String = "Basic "+ encoder.toString();

                   serv.headers = {"Authorization":prop};

                   //serv.headers["Authorization"] = "Basic " + encoder.toString();

                   serv.send();

                 }

       

                 private function getURL():void {

                    addAuthHeader(myService, "admin", "crypticpassw");

                 }

       

                  private function widgetResultHandler(event:ResultEvent):void

                  {

                      myText.text = event.result as XML;

                  }

       

                  private function widgetFaultHandler(event:FaultEvent):void

                  {

                      Alert.show(event.fault.message, "Oeps..." + event);

                  }

         

          ]]>

          </mx:Script>

       

       

      <mx:HTTPService id="myService"

                  url="http://localhost:8080/test/search/firstpage.xml"

                  resultFormat="e4x"

                          result="widgetResultHandler(event);"

                          fault="widgetFaultHandler(event);"/>

       

       

      <mx:Button id="go" label="GO" click="getURL()" x="97" y="145"/>

       

      <mx:TextArea id="myText" x="97" y="48" width="223" height="89"/>

      <mx:Label x="97" y="22" text="Stop the custom search"/>

       

       

       

      </mx:Application>

       

       

      Can anyone tell me how I can get this functionality to work. The numerous examples on the web all look like mine, but none works because the header is removed before sending the request to the server.

       

      Kind regards,

       

      Marc de Kwant