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:megharajdee...@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 <megharajdee...@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?
>
>

Reply via email to