3 Replies Latest reply on Jun 30, 2007 7:22 PM by Squee-D

    Problem with Authorization & URLRequest

    theodark
      Hi Everyone

      I've noticed this bug while trying to make an
      mp3 player that streams content from a protected
      directory.

      The following code was used in order to open the
      mp3 streams / files :
      quote:

      var oRequest : URLRequest = new URLRequest("<path_to_a_protected_directory_file_>");
      oRequest.method = URLRequestMethod.POST;
      oRequest.requestHeaders.push( new URLRequestHeader( "Authorization" , "basic " + "<user:pass_in_base64_encoding>") );
      m_SoundObj = new Sound();
      m_SoundObj.addEventListener( "ioError" , SoundObj_OnIOError );
      m_SoundObj.load(oRequest);

      The above always produces a browser authentication dialog.

      I tried to isolate the problem using a URLLoader but no such luck.
      The url loader failed also... A folk on a weblog said that only POST
      requests accept headers... added the post method, still nothing...

      I've ported the request mechanism using XMLHTTP in order
      to check out if there was anything wrong with my settings and
      it worked ok (using utf8 / iso-8859-7 charsets)... Flex still refuses
      to use the authentication info...

      Seems like the Sound Object only sees the url from
      the entire URLRequest object in order to open the file.

      Any ideas?
        • 1. Re: Problem with Authorization &amp; URLRequest
          oxtopus
          I get the same problem. In fact, when I retrieve a local file served out by PHP, I can't find any trace of the header.

          the code I'm using:

          var r:URLRequest = new URLRequest (URL);
          var login64 : String = Base64.encode (e + ":" + p);
          var authHeader:URLRequestHeader = new URLRequestHeader ("Authorization", "Basic " + login64);
          r.requestHeaders.push(authHeader);

          l = new URLLoader ();
          l.load(r);
          • 2. Re: Problem with Authorization &amp; URLRequest
            Squee-D
            My code, also not adding headers

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
            <mx:Script>
            <![CDATA[

            private function go():void {
            var request:URLRequest = new URLRequest(pollutedNamespaceDotCom.text); // the +".xml" makes me mad
            request.method = URLRequestMethod.POST;
            request.requestHeaders = new Array(new URLRequestHeader(headerName.text,headerValue.text));
            var loader:URLLoader = new URLLoader(request);
            }


            ]]>
            </mx:Script>

            <mx:Button x="287" y="142" label="Submit" click="go()"/>
            <mx:TextInput x="10" y="36" id="headerName" text="Foo"/>
            <mx:TextInput x="192" y="36" id="headerValue" text="Bar"/>
            <mx:Label x="10" y="10" text="Header Name"/>
            <mx:Label x="192" y="10" text="Header Value"/>
            <mx:Label x="10" y="66" text="URL"/>
            <mx:TextInput id="pollutedNamespaceDotCom" x="10" y="92" width="342" text=" http://dev2.ivistra.com/~rasheed/"/>

            </mx:Application>
            • 3. Re: Problem with Authorization &amp; URLRequest
              Squee-D Level 1
              And the following shows the problem fixed. You MUST set some data on the request like so:

              request.data = "fooooooo";

              I'm going to guess request.data = " "; will suffice and not break too much on the other end

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
              <mx:Script>
              <![CDATA[

              private function go():void {
              var request:URLRequest = new URLRequest(pollutedNamespaceDotCom.text); // the +".xml" makes me mad
              request.method = URLRequestMethod.POST;
              request.data = "fooooooo";
              request.requestHeaders = new Array(new URLRequestHeader(headerName.text,headerValue.text));
              var loader:URLLoader = new URLLoader(request);
              }


              ]]>
              </mx:Script>

              <mx:Button x="287" y="142" label="Submit" click="go()"/>
              <mx:TextInput x="10" y="36" id="headerName" text="Foo"/>
              <mx:TextInput x="192" y="36" id="headerValue" text="Bar"/>
              <mx:Label x="10" y="10" text="Header Name"/>
              <mx:Label x="192" y="10" text="Header Value"/>
              <mx:Label x="10" y="66" text="URL"/>
              <mx:TextInput id="pollutedNamespaceDotCom" x="10" y="92" width="342" text=" http://dev2.ivistra.com/~rasheed/"/>

              </mx:Application>