You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Deepak MS <me...@gmail.com> on 2015/03/16 15:00:52 UTC

HTTP Basic Authentication for URLRequest

Hello,
I'm trying to download a file from the server which requires basic
authentication(need to enter user name and password to access).

I came across these links:
http://stackoverflow.com/questions/509219/flex-3-how-to-support-http-authentication-urlrequest

http://johncblandii.com/2011/07/flex-quick-tip-urlrequest-basic-auth.html

http://blog.derraab.com/2010/02/25/urlrequest-with-http-authentication/

Tried all of it. I either get IO error or I get windows authentication
popup window when I run the mobile app on my desktop.

None of it seem to work. I'm using Flex4.14\AIR16.

Screenshot:
http://pbrd.co/18wmsZK


Code that I have been trying:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark" title="Contact" >
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import mx.utils.Base64Encoder;

            private var remoteURLStreamer:URLStream= new URLStream();

            private var pathRemote:String = '
http://myserver.com/datafiles/myfile.zip';

            private function startRemoteFileDownload():void
            {
                URLRequestDefaults.setLoginCredentialsForHost('
www.myserver.com','myusername','mypassword'); // not working
                remoteURLStreamer.addEventListener(ProgressEvent.PROGRESS,
remoteURLStreamerProgressHandler);
                remoteURLStreamer.addEventListener(IOErrorEvent.IO_ERROR,
remoteURLStreamerIOErrorHandler);

remoteURLStreamer.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
remoteURLStreamerSecurityErrorHandler);

                var req:URLRequest = new URLRequest(pathRemote);

                req.method = URLRequestMethod.POST;

                req.data = new URLVariables("name=John+Doe"); //(one post
suggests to pass dummy parameters to data) not working

                var encoder:Base64Encoder = new Base64Encoder();
                encoder.insertNewLines = true;
                encoder.encode("myusername:mypassword");


                var credsHeader:URLRequestHeader = new
URLRequestHeader("Authorization", "Basic " + encoder.toString()); //not
working
                req.requestHeaders.push(credsHeader);
                remoteURLStreamer.load(req);

            }

            private function
remoteURLStreamerProgressHandler(event:ProgressEvent):void
            {

                switch (event.type)
                {
                    case "progress":
                        lb.text = event.bytesLoaded.toString();
                        break;
                }
            }



            private function
remoteURLStreamerIOErrorHandler(event:IOErrorEvent):void
            {
                lb.text = 'IOError';
            }

            private function
remoteURLStreamerSecurityErrorHandler(event:SecurityErrorEvent):void
            {
                lb.text = 'SecurityError';
            }


            protected function button1_clickHandler(event:MouseEvent):void
            {
                startRemoteFileDownload();
            }

        ]]>
    </fx:Script>

    <s:Button label="hello" click="button1_clickHandler(event)"/>
    <s:Label id="lb" text="Hello"/>
</s:View>



Can you kindly let me know if there is something going wrong here? Or is
there any other way to make it work?

Re: HTTP Basic Authentication for URLRequest

Posted by Tom Chiverton <tc...@extravision.com>.
Do you have a network packet log ?

Tom

On 24/03/15 04:25, Deepak MS wrote:
> Any help on this please? I still haven't found any solution for this. I
> keep getting username\password prompt on the simulator. ;(
>
> On Mon, Mar 16, 2015 at 7:30 PM, Deepak MS <me...@gmail.com> wrote:
>
>> Hello,
>> I'm trying to download a file from the server which requires basic
>> authentication(need to enter user name and password to access).
>>
>> I came across these links:
>>
>> http://stackoverflow.com/questions/509219/flex-3-how-to-support-http-authentication-urlrequest
>>
>> http://johncblandii.com/2011/07/flex-quick-tip-urlrequest-basic-auth.html
>>
>> http://blog.derraab.com/2010/02/25/urlrequest-with-http-authentication/
>>
>> Tried all of it. I either get IO error or I get windows authentication
>> popup window when I run the mobile app on my desktop.
>>
>> None of it seem to work. I'm using Flex4.14\AIR16.
>>
>> Screenshot:
>> http://pbrd.co/18wmsZK
>>
>>
>> Code that I have been trying:
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
>>          xmlns:s="library://ns.adobe.com/flex/spark" title="Contact" >
>>      <s:layout>
>>          <s:VerticalLayout/>
>>      </s:layout>
>>      <fx:Script>
>>          <![CDATA[
>>              import mx.events.FlexEvent;
>>              import mx.utils.Base64Encoder;
>>
>>              private var remoteURLStreamer:URLStream= new URLStream();
>>
>>              private var pathRemote:String = '
>> http://myserver.com/datafiles/myfile.zip';
>>
>>              private function startRemoteFileDownload():void
>>              {
>>                  URLRequestDefaults.setLoginCredentialsForHost('
>> www.myserver.com','myusername','mypassword'); // not working
>>                  remoteURLStreamer.addEventListener(ProgressEvent.PROGRESS,
>> remoteURLStreamerProgressHandler);
>>                  remoteURLStreamer.addEventListener(IOErrorEvent.IO_ERROR,
>> remoteURLStreamerIOErrorHandler);
>>
>> remoteURLStreamer.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
>> remoteURLStreamerSecurityErrorHandler);
>>
>>                  var req:URLRequest = new URLRequest(pathRemote);
>>
>>                  req.method = URLRequestMethod.POST;
>>
>>                  req.data = new URLVariables("name=John+Doe"); //(one post
>> suggests to pass dummy parameters to data) not working
>>
>>                  var encoder:Base64Encoder = new Base64Encoder();
>>                  encoder.insertNewLines = true;
>>                  encoder.encode("myusername:mypassword");
>>
>>
>>                  var credsHeader:URLRequestHeader = new
>> URLRequestHeader("Authorization", "Basic " + encoder.toString()); //not
>> working
>>                  req.requestHeaders.push(credsHeader);
>>                  remoteURLStreamer.load(req);
>>
>>              }
>>
>>              private function
>> remoteURLStreamerProgressHandler(event:ProgressEvent):void
>>              {
>>
>>                  switch (event.type)
>>                  {
>>                      case "progress":
>>                          lb.text = event.bytesLoaded.toString();
>>                          break;
>>                  }
>>              }
>>
>>
>>
>>              private function
>> remoteURLStreamerIOErrorHandler(event:IOErrorEvent):void
>>              {
>>                  lb.text = 'IOError';
>>              }
>>
>>              private function
>> remoteURLStreamerSecurityErrorHandler(event:SecurityErrorEvent):void
>>              {
>>                  lb.text = 'SecurityError';
>>              }
>>
>>
>>              protected function button1_clickHandler(event:MouseEvent):void
>>              {
>>                  startRemoteFileDownload();
>>              }
>>
>>          ]]>
>>      </fx:Script>
>>
>>      <s:Button label="hello" click="button1_clickHandler(event)"/>
>>      <s:Label id="lb" text="Hello"/>
>> </s:View>
>>
>>
>>
>> Can you kindly let me know if there is something going wrong here? Or is
>> there any other way to make it work?
>>
>>
>
> ______________________________________________________________________
> This email has been scanned by the Symantec Email Security.cloud service.
> For more information please visit http://www.symanteccloud.com
> ______________________________________________________________________


RE: HTTP Basic Authentication for URLRequest

Posted by Kessler CTR Mark J <ma...@usmc.mil>.
Could always try SSL with the UN/PW in the URL [1].


[1] http://stackoverflow.com/questions/2716990/http-basic-authentication-credentials-passed-in-url-and-encryption

-Mark

-----Original Message-----
From: Deepak MS [mailto:megharajdeepak@gmail.com]
Sent: Tuesday, March 24, 2015 12:26 AM
To: users@flex.apache.org
Subject: Re: HTTP Basic Authentication for URLRequest

Any help on this please? I still haven't found any solution for this. I
keep getting username\password prompt on the simulator. ;(

On Mon, Mar 16, 2015 at 7:30 PM, Deepak MS <me...@gmail.com> wrote:

> Hello,
> I'm trying to download a file from the server which requires basic
> authentication(need to enter user name and password to access).
>
> I came across these links:
>
> http://stackoverflow.com/questions/509219/flex-3-how-to-support-http-authentication-urlrequest
>
> http://johncblandii.com/2011/07/flex-quick-tip-urlrequest-basic-auth.html
>
> http://blog.derraab.com/2010/02/25/urlrequest-with-http-authentication/
>
> Tried all of it. I either get IO error or I get windows authentication
> popup window when I run the mobile app on my desktop.
>
> None of it seem to work. I'm using Flex4.14\AIR16.
>
> Screenshot:
> http://pbrd.co/18wmsZK
>
>
> Code that I have been trying:
>
> <?xml version="1.0" encoding="utf-8"?>
> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
>         xmlns:s="library://ns.adobe.com/flex/spark" title="Contact" >
>     <s:layout>
>         <s:VerticalLayout/>
>     </s:layout>
>     <fx:Script>
>         <![CDATA[
>             import mx.events.FlexEvent;
>             import mx.utils.Base64Encoder;
>
>             private var remoteURLStreamer:URLStream= new URLStream();
>
>             private var pathRemote:String = '
> http://myserver.com/datafiles/myfile.zip';
>
>             private function startRemoteFileDownload():void
>             {
>                 URLRequestDefaults.setLoginCredentialsForHost('
> www.myserver.com','myusername','mypassword'); // not working
>                 remoteURLStreamer.addEventListener(ProgressEvent.PROGRESS,
> remoteURLStreamerProgressHandler);
>                 remoteURLStreamer.addEventListener(IOErrorEvent.IO_ERROR,
> remoteURLStreamerIOErrorHandler);
>
> remoteURLStreamer.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
> remoteURLStreamerSecurityErrorHandler);
>
>                 var req:URLRequest = new URLRequest(pathRemote);
>
>                 req.method = URLRequestMethod.POST;
>
>                 req.data = new URLVariables("name=John+Doe"); //(one post
> suggests to pass dummy parameters to data) not working
>
>                 var encoder:Base64Encoder = new Base64Encoder();
>                 encoder.insertNewLines = true;
>                 encoder.encode("myusername:mypassword");
>
>
>                 var credsHeader:URLRequestHeader = new
> URLRequestHeader("Authorization", "Basic " + encoder.toString()); //not
> working
>                 req.requestHeaders.push(credsHeader);
>                 remoteURLStreamer.load(req);
>
>             }
>
>             private function
> remoteURLStreamerProgressHandler(event:ProgressEvent):void
>             {
>
>                 switch (event.type)
>                 {
>                     case "progress":
>                         lb.text = event.bytesLoaded.toString();
>                         break;
>                 }
>             }
>
>
>
>             private function
> remoteURLStreamerIOErrorHandler(event:IOErrorEvent):void
>             {
>                 lb.text = 'IOError';
>             }
>
>             private function
> remoteURLStreamerSecurityErrorHandler(event:SecurityErrorEvent):void
>             {
>                 lb.text = 'SecurityError';
>             }
>
>
>             protected function button1_clickHandler(event:MouseEvent):void
>             {
>                 startRemoteFileDownload();
>             }
>
>         ]]>
>     </fx:Script>
>
>     <s:Button label="hello" click="button1_clickHandler(event)"/>
>     <s:Label id="lb" text="Hello"/>
> </s:View>
>
>
>
> Can you kindly let me know if there is something going wrong here? Or is
> there any other way to make it work?
>
>

Re: HTTP Basic Authentication for URLRequest

Posted by Deepak MS <me...@gmail.com>.
Any help on this please? I still haven't found any solution for this. I
keep getting username\password prompt on the simulator. ;(

On Mon, Mar 16, 2015 at 7:30 PM, Deepak MS <me...@gmail.com> wrote:

> Hello,
> I'm trying to download a file from the server which requires basic
> authentication(need to enter user name and password to access).
>
> I came across these links:
>
> http://stackoverflow.com/questions/509219/flex-3-how-to-support-http-authentication-urlrequest
>
> http://johncblandii.com/2011/07/flex-quick-tip-urlrequest-basic-auth.html
>
> http://blog.derraab.com/2010/02/25/urlrequest-with-http-authentication/
>
> Tried all of it. I either get IO error or I get windows authentication
> popup window when I run the mobile app on my desktop.
>
> None of it seem to work. I'm using Flex4.14\AIR16.
>
> Screenshot:
> http://pbrd.co/18wmsZK
>
>
> Code that I have been trying:
>
> <?xml version="1.0" encoding="utf-8"?>
> <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
>         xmlns:s="library://ns.adobe.com/flex/spark" title="Contact" >
>     <s:layout>
>         <s:VerticalLayout/>
>     </s:layout>
>     <fx:Script>
>         <![CDATA[
>             import mx.events.FlexEvent;
>             import mx.utils.Base64Encoder;
>
>             private var remoteURLStreamer:URLStream= new URLStream();
>
>             private var pathRemote:String = '
> http://myserver.com/datafiles/myfile.zip';
>
>             private function startRemoteFileDownload():void
>             {
>                 URLRequestDefaults.setLoginCredentialsForHost('
> www.myserver.com','myusername','mypassword'); // not working
>                 remoteURLStreamer.addEventListener(ProgressEvent.PROGRESS,
> remoteURLStreamerProgressHandler);
>                 remoteURLStreamer.addEventListener(IOErrorEvent.IO_ERROR,
> remoteURLStreamerIOErrorHandler);
>
> remoteURLStreamer.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
> remoteURLStreamerSecurityErrorHandler);
>
>                 var req:URLRequest = new URLRequest(pathRemote);
>
>                 req.method = URLRequestMethod.POST;
>
>                 req.data = new URLVariables("name=John+Doe"); //(one post
> suggests to pass dummy parameters to data) not working
>
>                 var encoder:Base64Encoder = new Base64Encoder();
>                 encoder.insertNewLines = true;
>                 encoder.encode("myusername:mypassword");
>
>
>                 var credsHeader:URLRequestHeader = new
> URLRequestHeader("Authorization", "Basic " + encoder.toString()); //not
> working
>                 req.requestHeaders.push(credsHeader);
>                 remoteURLStreamer.load(req);
>
>             }
>
>             private function
> remoteURLStreamerProgressHandler(event:ProgressEvent):void
>             {
>
>                 switch (event.type)
>                 {
>                     case "progress":
>                         lb.text = event.bytesLoaded.toString();
>                         break;
>                 }
>             }
>
>
>
>             private function
> remoteURLStreamerIOErrorHandler(event:IOErrorEvent):void
>             {
>                 lb.text = 'IOError';
>             }
>
>             private function
> remoteURLStreamerSecurityErrorHandler(event:SecurityErrorEvent):void
>             {
>                 lb.text = 'SecurityError';
>             }
>
>
>             protected function button1_clickHandler(event:MouseEvent):void
>             {
>                 startRemoteFileDownload();
>             }
>
>         ]]>
>     </fx:Script>
>
>     <s:Button label="hello" click="button1_clickHandler(event)"/>
>     <s:Label id="lb" text="Hello"/>
> </s:View>
>
>
>
> Can you kindly let me know if there is something going wrong here? Or is
> there any other way to make it work?
>
>

Re: HTTP Basic Authentication for URLRequest

Posted by douglowder <dl...@tpocc.org>.
You should be aware that hard-coding the authentication parameters as you
have done in the examples makes those values visible to anyone with the
application.  Running the app is not even necessary; just examining the
file, such as with a decompiler, will make the username and password values
visible, and probably defeat the purpose of requiring authentication in the
first place.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/HTTP-Basic-Authentication-for-URLRequest-tp9803p9945.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: HTTP Basic Authentication for URLRequest

Posted by Kessler CTR Mark J <ma...@usmc.mil>.
I believe the separation of the header from the body is the double CR.  It's been a while since I've seen the standard.

-Mark

-----Original Message-----
From: Deepak MS [mailto:megharajdeepak@gmail.com]
Sent: Wednesday, April 01, 2015 2:11 AM
To: users@flex.apache.org
Subject: Re: HTTP Basic Authentication for URLRequest

After all the experiments, this is what I have got.

Om, as3httpclient isn't giving me a progress event(I need progress event to
write the downloading file data in chunks). I thought onData event would
give me progress, but it isn't. Is there any other event I can try?

Kevin,
Your solution worked well. It authenticated the URL file(zip file). I did
not get username\password popup. It writes the file and creates it. But it
isn't opening the zip file. When I looked at the file size, I could see
320bytes of data is more than original file size. I think that's why file
is reported as corrupt and it is not opening.

This is what I am doing under progress event to create the zip file(it just
appends the data that we get in progress)

private function socket_dataHandler(event:ProgressEvent):void
{
    //the tricky part, figuring out what to do with the raw data
   // trace(socket.readUTFBytes(event.bytesLoaded));

localZipFile =
File.desktopDirectory.resolvePath('C:\\Desktop\\dowloadedZipFile.zip');
var bytes:ByteArray = new ByteArray();
socket.readBytes(bytes,bytes.length);
fileStream = new FileStream();
fileStream.addEventListener(Event.CLOSE, fileClosed);
fileStream.addEventListener(IOErrorEvent.IO_ERROR, onFSIOError);
fileStream.open( localZipFile, localZipFile.exists ?
FileMode.APPEND:FileMode.WRITE);
fileStream.writeBytes( bytes );
fileStream.close();

}

After that, I tried to download and write a simple text file instead of zip
file. The text file just has 'Hello' written in it. This time, file got
downloaded and got written on the disk. But when I opened it, this is what
I got:

"HTTP/1.1 200 OK
Cache-Control: max-age=31536000
Content-Type: text/plain
Last-Modified: Wed, 01 Apr 2015 05:20:10 GMT
Accept-Ranges: bytes
ETag: "859b56863b6cd01:0"
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Wed, 01 Apr 2015 05:55:05 GMT
Connection: close
Content-Length: 5

Hello"


And I feel this is the reason, zip is getting corrupted as it has some
extra header details in it.
So how can I avoid writing this header part to my zip file?

Re: HTTP Basic Authentication for URLRequest

Posted by Deepak MS <me...@gmail.com>.
After all the experiments, this is what I have got.

Om, as3httpclient isn't giving me a progress event(I need progress event to
write the downloading file data in chunks). I thought onData event would
give me progress, but it isn't. Is there any other event I can try?

Kevin,
Your solution worked well. It authenticated the URL file(zip file). I did
not get username\password popup. It writes the file and creates it. But it
isn't opening the zip file. When I looked at the file size, I could see
320bytes of data is more than original file size. I think that's why file
is reported as corrupt and it is not opening.

This is what I am doing under progress event to create the zip file(it just
appends the data that we get in progress)

private function socket_dataHandler(event:ProgressEvent):void
{
    //the tricky part, figuring out what to do with the raw data
   // trace(socket.readUTFBytes(event.bytesLoaded));

localZipFile =
File.desktopDirectory.resolvePath('C:\\Desktop\\dowloadedZipFile.zip');
var bytes:ByteArray = new ByteArray();
socket.readBytes(bytes,bytes.length);
fileStream = new FileStream();
fileStream.addEventListener(Event.CLOSE, fileClosed);
fileStream.addEventListener(IOErrorEvent.IO_ERROR, onFSIOError);
fileStream.open( localZipFile, localZipFile.exists ?
FileMode.APPEND:FileMode.WRITE);
fileStream.writeBytes( bytes );
fileStream.close();

}

After that, I tried to download and write a simple text file instead of zip
file. The text file just has 'Hello' written in it. This time, file got
downloaded and got written on the disk. But when I opened it, this is what
I got:

"HTTP/1.1 200 OK
Cache-Control: max-age=31536000
Content-Type: text/plain
Last-Modified: Wed, 01 Apr 2015 05:20:10 GMT
Accept-Ranges: bytes
ETag: "859b56863b6cd01:0"
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Wed, 01 Apr 2015 05:55:05 GMT
Connection: close
Content-Length: 5

Hello"


And I feel this is the reason, zip is getting corrupted as it has some
extra header details in it.
So how can I avoid writing this header part to my zip file?





On Sat, Mar 28, 2015 at 8:25 AM, kevin.godell <ke...@gmail.com>
wrote:

> I duplicated your situation with basic authentication and had the same
> trouble of not being able to include the Authentication header using
> urlstream.
> Using Socket will allow you to authenticate and access the protected file,
> but is a bit trickier.
>
> private var socket:Socket;
>
> private function connectSocket():void
> {
>     if (!socket)
>         socket = new Socket;
>         socket.addEventListener(Event.CONNECT,
> socket_connectHandler);//socket successfully connected
>         socket.addEventListener(IOErrorEvent.IO_ERROR,
> socket_IOErrorHandler);//socket failed to connect
>         socket.addEventListener(ProgressEvent.SOCKET_DATA,
> socket_dataHandler);//received data from socket
>         socket.addEventListener(Event.CLOSE, onSocketClose);//socket
> closed by
> server
>     }
>     socket.connect("website.com", 80);
> }
>
> private function socket_connectHandler(event:Event):void
> {
>     var b64:Base64Encoder = new Base64Encoder;
>     b64.encode("user1:user1Password");
>     var httpRequest:String = "GET /protected/testfile.txt
> HTTP/1.1\r\n";//might try 1.0 depending on situation
>     httpRequest += "Authorization: Basic " + b64.toString() + "\r\n\r\n";
>     socket.writeUTFBytes(httpRequest);
>     sock.flush();
> }
>
> private function socket_dataHandler(event:ProgressEvent):void
> {
>     //the tricky part, figuring out what to do with the raw data
>     trace(socket.readUTFBytes(event.bytesLoaded));
> }
>
>
>
>
>
>
> -----
> .
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/HTTP-Basic-Authentication-for-URLRequest-tp9803p9927.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: HTTP Basic Authentication for URLRequest

Posted by OmPrakash Muppirala <bi...@gmail.com>.
On Mar 27, 2015 9:01 PM, "kevin.godell" <ke...@gmail.com> wrote:
>
> I duplicated your situation with basic authentication and had the same
> trouble of not being able to include the Authentication header using
> urlstream.
> Using Socket will allow you to authenticate and access the protected file,
> but is a bit trickier.

Yes, I think this is best approach.   And is essentially what the
as3httpclient lib lets us do.

Thanks,
Om

>
> private var socket:Socket;
>
> private function connectSocket():void
> {
>     if (!socket)
>         socket = new Socket;
>         socket.addEventListener(Event.CONNECT,
> socket_connectHandler);//socket successfully connected
>         socket.addEventListener(IOErrorEvent.IO_ERROR,
> socket_IOErrorHandler);//socket failed to connect
>         socket.addEventListener(ProgressEvent.SOCKET_DATA,
> socket_dataHandler);//received data from socket
>         socket.addEventListener(Event.CLOSE, onSocketClose);//socket
closed by
> server
>     }
>     socket.connect("website.com", 80);
> }
>
> private function socket_connectHandler(event:Event):void
> {
>     var b64:Base64Encoder = new Base64Encoder;
>     b64.encode("user1:user1Password");
>     var httpRequest:String = "GET /protected/testfile.txt
> HTTP/1.1\r\n";//might try 1.0 depending on situation
>     httpRequest += "Authorization: Basic " + b64.toString() + "\r\n\r\n";
>     socket.writeUTFBytes(httpRequest);
>     sock.flush();
> }
>
> private function socket_dataHandler(event:ProgressEvent):void
> {
>     //the tricky part, figuring out what to do with the raw data
>     trace(socket.readUTFBytes(event.bytesLoaded));
> }
>
>
>
>
>
>
> -----
> .
> --
> View this message in context:
http://apache-flex-users.2333346.n4.nabble.com/HTTP-Basic-Authentication-for-URLRequest-tp9803p9927.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: HTTP Basic Authentication for URLRequest

Posted by "kevin.godell" <ke...@gmail.com>.
I duplicated your situation with basic authentication and had the same
trouble of not being able to include the Authentication header using
urlstream. 
Using Socket will allow you to authenticate and access the protected file,
but is a bit trickier.

private var socket:Socket;

private function connectSocket():void
{
    if (!socket)
        socket = new Socket;
        socket.addEventListener(Event.CONNECT,
socket_connectHandler);//socket successfully connected
        socket.addEventListener(IOErrorEvent.IO_ERROR,
socket_IOErrorHandler);//socket failed to connect
	socket.addEventListener(ProgressEvent.SOCKET_DATA,
socket_dataHandler);//received data from socket
	socket.addEventListener(Event.CLOSE, onSocketClose);//socket closed by
server
    }
    socket.connect("website.com", 80);
}

private function socket_connectHandler(event:Event):void
{
    var b64:Base64Encoder = new Base64Encoder;
    b64.encode("user1:user1Password");
    var httpRequest:String = "GET /protected/testfile.txt
HTTP/1.1\r\n";//might try 1.0 depending on situation
    httpRequest += "Authorization: Basic " + b64.toString() + "\r\n\r\n";
    socket.writeUTFBytes(httpRequest);
    sock.flush();
}

private function socket_dataHandler(event:ProgressEvent):void
{
    //the tricky part, figuring out what to do with the raw data
    trace(socket.readUTFBytes(event.bytesLoaded));
}






-----
.
--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/HTTP-Basic-Authentication-for-URLRequest-tp9803p9927.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.