Resolve shortened url in Android
How do I resolve a shortened ur开发者_JAVA百科l (bit.ly/dfasdfasf) to the re-directed url in android?
You have to request the URL and then inspect the response to determine where the server is redirecting you to. You can do this by using Android's HTTP libraries or Java Sockets. Alternatively, if you know it's a bit.ly URL, you can use their API to expand the shortened url.
You would probably want to use the Bit.ly API expand
function.
From the docs:
Given a bitly URL or hash (or multiple), /v3/expand decodes it and returns back the target URL
The HttpURLConnection class redirect the connection in a max of 5 jumps.
精彩评论