Java / Android example code for obtaining the real URL of the network redirection file
preface:
Today, I got a redirected URL when I used the URL provided by a third party to download files. Unfortunately, this URL is impossible for me to download files. At this point, you need to get the real URL of the redirected file.
Problem analysis:
In fact, when Java uses httpurlconnection to download, it will automatically download the reset file, but we can't know the real file name and file type of the target file. Use the following method to get the real URL
Solution:
It should be noted that after Android 4.0, network requests cannot be executed in the main thread
Finally, don't forget to add network permissions
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.