So I have a short URL that gives me 3 urls , and all I want is to extract the first URL that is on this image
So, from the short URL : https://myweb.attn.tv/EVD I got these 3 redirects, what I want is only to get the first one, I have tried with this code but without success
private fun extractUrl(url: String) {
var address = URL(url)
var connection: HttpURLConnection? = null
try {
connection = address.openConnection(Proxy.NO_PROXY) as HttpURLConnection
connection.setInstanceFollowRedirects(false)
connection.connect()
val expandedURL: String = connection.getHeaderField("Location")
Logger.debug("Expanded URL${expandedURL} ")
val expanded = URL(expandedURL)
address = expanded
} catch (e: Throwable) {
println("Problem while expanding {}$address$e")
} finally {
if (connection != null) {
//System.out.println(connection.inputStream)
}
}
Logger.debug("Original URL${address} $connection.requestc")
}
is there another way to extract the first redirect from this link ?
Thanks
