flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "kevin.godell" <kevin.god...@gmail.com>
Subject Re: HTTP Basic Authentication for URLRequest
Date Sat, 28 Mar 2015 02:55:39 GMT
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.

Mime
View raw message