The use of network resources to download URL (simple plate)

The use of network resources to download URL

NetEase cloud pay to download songs for example:

1, the following code written in IDEA

package pers.mobian.udp;


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class TestDownURL {
    public static void main(String[] args) throws IOException {
        //1、参数为请求的目的地址
        URL url = new URL("");

        //2、连接到这个资源HTTP
        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
        InputStream inputStream = urlConnection.getInputStream();

        //3、将资源写入目标对象
        FileOutputStream fos = new FileOutputStream("");
        byte[] buffer = new byte[1024];
        int len;
        while ((len = inputStream.read(buffer))!=-1){
            fos.write(buffer,0,len);
        }
        
        //4、关闭资源
        fos.close();
        inputStream.close();
        urlConnection.disconnect();
    }
}

2, open the corresponding player interface in the browser

3, right click -> Check -> Network -> XHR

4, click play, capture the corresponding request address (the song is the end .m4a format)

5, copy the corresponding address code prior to backfilling

6, the implementation of the program

7, with the open player corresponding folder can

Guess you like

Origin www.cnblogs.com/mobian/p/12222713.html