mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-03 20:27:58 +08:00
HttpUtil添加downloadBytes方法✒️
This commit is contained in:
parent
1b4276c211
commit
145ea0820d
@ -356,6 +356,26 @@ public class HttpUtil {
|
|||||||
return response.writeBody(out, isCloseOut, streamProgress);
|
return response.writeBody(out, isCloseOut, streamProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载远程文件数据
|
||||||
|
*
|
||||||
|
* @param url 请求的url
|
||||||
|
* @return 文件数据
|
||||||
|
*/
|
||||||
|
public static byte[] downloadBytes(String url) {
|
||||||
|
if (StrUtil.isBlank(url)) {
|
||||||
|
throw new NullPointerException("[url] is null!");
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpRequest request = new HttpRequest(url);
|
||||||
|
request.setFollowRedirects(true);
|
||||||
|
final HttpResponse response = request.executeAsync();
|
||||||
|
if (false == response.isOk()) {
|
||||||
|
throw new HttpException("Server response error with status code: [{}]", response.getStatus());
|
||||||
|
}
|
||||||
|
return response.bodyBytes();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将Map形式的Form表单数据转换为Url参数形式,不做编码
|
* 将Map形式的Form表单数据转换为Url参数形式,不做编码
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user