Java gets the real URL of the network redirection file

Source: Internet
Author: User

In fact, Java use httpurlconnection download, will automatically under the load-directed file, but we do not know the target file of the real filename, file type, the following method can get the real URL, the following is an example of a Youku video.

Importjava.net.HttpURLConnection;ImportJava.net.URL;Importjava.util.ArrayList; Public classTest2 { Public Static voidMain (string[] args)throwsException {String str= "Http://f.youku.com/player/getFlvPath/sid/130258503437697_01/st/flv/fileid/ 03000201004da277e47ac503e2c7936b543e15-dfed-ee85-31e0-869a7be2f5b8? K=457eb55affadc5c5161b9af9&hd=0 "; URL URL=NewURL (str); HttpURLConnection Conn=(HttpURLConnection) url.openconnection ();        Conn.getresponsecode (); String Realurl=Conn.geturl (). toString ();        Conn.disconnect (); System.out.println ("Real URL:" +Realurl); }}

Java gets the real URL of the network redirection file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.