Reputation: 149
I have an RSS feed that I need to read, but you need to log in with a valid username and password to get the feed. I was wondering if or how to do this using Actionscript 3.
Right now I have a very simple script that just gets the xml from a provided url and outputs the xml to the console.
I've verified that it works with a feed that doesn't require authentication.
Let me know if code or anything more specific is needed.
Thanks in advance!
Upvotes: 1
Views: 401
Reputation: 2881
If you're using an http service, you can do basic authorization with by extending the HTTPService :
package{
import mx.rpc.AsyncToken;
import mx.rpc.http.mxml.HTTPService;
import mx.utils.Base64Encoder;
public class HTTPServiceAuth extends HTTPService
{
public var username : String = '';
public var password : String = '';
public function HTTPServiceAuth(rootURL:String=null, destination:String=null)
{
super(rootURL, destination);
}
override public function send(parameters:Object=null ):AsyncToken {
var enc : Base64Encoder = new Base64Encoder();
enc.insertNewLines = false;
enc.encode(username + ':' + password );
this.headers = {Authorization:"Basic " + enc.toString())};
super.send(parameters);
}
}
}
You use it the same way except you can specify a username and password :
<local:HTTPServiceAuth url="http://www.domain.com/feed/etc" username="myUsername" password="myPassword" ...rest of standard args, etc... />
Upvotes: 1