Actionscript 3: Reading an RSS feed that requires authentication

 ̄綄美尐妖づ 提交于 2019-12-11 07:24:08

问题


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!


回答1:


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... />


来源:https://stackoverflow.com/questions/6739111/actionscript-3-reading-an-rss-feed-that-requires-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!