public static byte[] loadFromUrl(String url) throws IOException {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader(RemoteFileUtil.REQUEST_HEADER_X_REQ, RemoteFileUtil.REQUEST_HEADER_X_REQ_NAME);
httpGet.setHeader(RemoteFileUtil.REQUEST_HEADER_X_TRACE, ContextHolderEx.getSourceId());
HttpResponse httpResponse = httpClient.execute(httpGet);
boolean isJson = httpResponse.getEntity().getContentType().getValue().contains("json");
if (isJson) {
String message = EntityUtils.toString(httpResponse.getEntity(), StandardCharsets.UTF_8);
log.warn("文件下載失敗:{}", message);
throw new IllegalArgumentException(JSON.parseObject(message).getString("message"));
}
return EntityUtils.toByteArray(httpResponse.getEntity());
}
}