《2019/04/12》java下载抖音视频

java下载抖音视频

下载抖音视频,获取到抖音视频的下载地址之后,类似:

String url = "https://aweme.snssdk.com/aweme/v1/play/?video_id=v0300fbd0000bhkfgq7jofsleq3pk120&line=0&ratio=540p&watermark=1&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0&logo_name=aweme";

使用URLConnection不能直接下来,使用OkHttp则可以:
添加pom依赖:


    com.squareup.okhttp3
    okhttp
    3.13.1

	@RequestMapping(value = "/getVideo")
    public void test(HttpServletResponse res) throws IOException{

        String url = "https://aweme.snssdk.com/aweme/v1/play/?video_id=v0300fbd0000bhkfgq7jofsleq3pk120&line=0&ratio=540p&watermark=1&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0&logo_name=aweme";
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .get()
                .build();
        Response response = client.newCall(request).execute();
        //创建接收文件的流
        //File file = new File( "D:\\" + fileName + ".mp4");
        //OutputStream outputStream = new FileOutputStream(file);

        OutputStream outputStream = res.getOutputStream();
        //将responseBody截取并写入到指定文件路径下
        outputStream.write(response.body().bytes());
        outputStream.flush();
        outputStream.close();
    }

你可能感兴趣的:(java技术,#,------杂项,抖音视频,OkHttp)