Remote Image with basic authentication?

假装没事ソ 提交于 2019-12-11 23:17:47

问题


I would like to load a an image from an external domain and I have the below so far:

            private function get_coverArt(coverArtID:String):void
        {
            var requestString:String = "/rest/getCoverArt.view?v=1.5.0&c=AirSub&id=" + coverArtID;
            var requestURL:String = subServerURL + requestString;

            myCoverArtLoader = new URLLoader();
            var myRequest:URLRequest = new URLRequest();

            var authHeader:URLRequestHeader = new URLRequestHeader();
            authHeader.name = 'Authorization';
            authHeader.value = 'Basic ' + credentials;

            myRequest.requestHeaders.push(authHeader);
            myRequest.url = requestURL;
            myRequest.method = URLRequestMethod.GET;
            myCoverArtLoader.dataFormat = URLLoaderDataFormat.BINARY;

            myCoverArtLoader.addEventListener(Event.COMPLETE, set_coverArt);
            myCoverArtLoader.load(myRequest);   

        }

        private function set_coverArt(evt:Event) : void {
            coverArtImg = new Image();

            var loader:Loader = new Loader();
            loader.loadBytes(myCoverArtLoader.data);
            coverArtImg.source = loader;
        }

This does not seem to work - any help?

Thanks!


回答1:


Try setting the source directly like so:

        private function set_coverArt(evt:Event) : void {
            coverArtImg = new Image();
            coverArtImg.source = myCoverArtLoader.data;
        }

Also, check your authentication, here's a question I answered regarding the auth :

Actionscript 3: Reading an RSS feed that requires authentication



来源:https://stackoverflow.com/questions/6805957/remote-image-with-basic-authentication

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