This commit is contained in:
Looly
2020-05-30 07:41:50 +08:00
parent fce8c35a82
commit 4a302fc2d8
4 changed files with 25 additions and 13 deletions

View File

@@ -353,20 +353,19 @@ public class HttpUtil {
}
/**
* 下载远程文件数据
* 下载远程文件数据支持30x跳转
*
* @param url 请求的url
* @param url 请求的url
* @return 文件数据
* @since 5.3.6
*/
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();
final HttpResponse response = HttpRequest.get(url)
.setFollowRedirects(true).executeAsync();
if (false == response.isOk()) {
throw new HttpException("Server response error with status code: [{}]", response.getStatus());
}