|
@ -199,13 +199,6 @@ public class HttpClientUtil {
|
|
|
|
|
|
/**
|
|
|
* 发送File
|
|
|
*
|
|
|
* @param filePath 文件路径
|
|
|
* @param params 参数
|
|
|
* @param url http路径
|
|
|
* @param username
|
|
|
* @param password
|
|
|
* @return
|
|
|
*/
|
|
|
public static File downLoadFileByBase64(String filePath, Map<String, Object> params, String url, String username, String password) {
|
|
|
File file = null;
|
|
@ -264,25 +257,21 @@ public class HttpClientUtil {
|
|
|
return file;
|
|
|
}
|
|
|
|
|
|
public static File downLoadFile(String filePath, Map<String, Object> params, String url, String username, String password) {
|
|
|
/**
|
|
|
* 下载文件
|
|
|
*/
|
|
|
public static File downLoadFile(String filePath, String url, String username, String password) {
|
|
|
File file = null;
|
|
|
CloseableHttpResponse response = null;
|
|
|
List<BasicNameValuePair> jsonParams = new ArrayList<>();
|
|
|
CloseableHttpClient httpclient = getCloseableHttpClient(null);
|
|
|
|
|
|
try {
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
HttpGet httpGet = new HttpGet(url);
|
|
|
//设置请求信息
|
|
|
RequestConfig requestConfig = RequestConfig.custom().
|
|
|
setAuthenticationEnabled(true).build();
|
|
|
//设置参数
|
|
|
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
|
|
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
|
|
formparams.add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
|
|
|
}
|
|
|
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
|
|
|
httpPost.setEntity(entity);
|
|
|
httpPost.setConfig(requestConfig);
|
|
|
|
|
|
if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) {
|
|
|
//需要验证
|
|
|
HttpClientContext context = HttpClientContext.create();
|
|
@ -291,9 +280,9 @@ public class HttpClientUtil {
|
|
|
credsProvider.setCredentials(new org.apache.http.auth.AuthScope(org.apache.http.auth.AuthScope.ANY_HOST, org.apache.http.auth.AuthScope.ANY_PORT),
|
|
|
new org.apache.http.auth.UsernamePasswordCredentials(username, password));
|
|
|
context.setCredentialsProvider(credsProvider);
|
|
|
response = httpclient.execute(httpPost, context);
|
|
|
response = httpclient.execute(httpGet, context);
|
|
|
} else {
|
|
|
response = httpclient.execute(httpPost);
|
|
|
response = httpclient.execute(httpGet);
|
|
|
}
|
|
|
HttpEntity httpEntity = response.getEntity();
|
|
|
InputStream is = httpEntity.getContent();
|