抖音字符视频java_分享一波原创java 获取抖音无水印视频源码

[Java] 纯文本查看 复制代码public static String doGet(String url) {

// 创建Httpclient对象

CloseableHttpClient httpclient = HttpClients.createDefault();

String resultString = "";

CloseableHttpResponse response = null;

try {

// 创建uri

URIBuilder builder = new URIBuilder(url);

// if (param != null) {

// for (String key : param.keySet()) {

// builder.addParameter(key, param.get(key));

// }

// }

URI uri = builder.build();

// 创建http GET请求

HttpGet httpGet = new HttpGet(uri);

// 設置httpGet的头部參數信息 此处必不可少,伪装成浏览器访问

httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");

httpGet.setHeader("Accept-Charset", "GB2312,utf-8;q=0.7,*;q=0.7");

httpGet.setHeader("Accept-Encoding", "gzip, deflate, sdch, br");

httpGet.setHeader("Accept-Language", "zh-cn,zh;q=0.8");

httpGet.setHeader("User-Agent",

"Mozilla/5.0 (iPod; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25");

// 执行请求

HttpContext httpContext = new BasicHttpContext();

response = httpclient.execute(httpGet, httpContext);

Object attribute = httpContext.getAttribute("http.request");

// 判断返回状态是否为200

if (response.getStatusLine().getStatusCode() == 200) {

HttpHost targetHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

// 获取实际的请求对象的URI,即重定向之后的地址

HttpEntity entity = response.getEntity();

// String s = EntityUtils.toString(entity, "UTF-8");

HttpUriRequest realRequest = (HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST);

return (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST)

+ ((HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST)).getURI().toString();

}

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

if (response != null) {

response.close();

}

httpclient.close();

} catch (IOException e) {

e.printStackTrace();

}

}

return resultString;

}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部