简体   繁体   中英

How to get the final URL from a redirect in AS3?

I need to get the final URL from a link that gets redirected. (eg if someone is using a URL shortener)

bit.ly/foobar ->redirect-> http://example.com

What the fastest way to do this in AS3? Thanks you

Since you are using AIR, you can listen for an HTTPStatusEvent.HTTP_RESPONSE_STATUS event:

var urlLoader:URLLoader = new URLLoader(new URLRequest("http://bit.ly/1bdDlXc"));
urlLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, urlLoader_httpResponseStatus);

function urlLoader_httpResponseStatus(e:HTTPStatusEvent):void 
{
        trace(e.redirected, e.responseURL);
}

The result of the above trace is true http://www.google.com/

This event gives you information about whether the URL was redirected and what the new URL is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM