parent
e3a7cee548
commit
fb2c71eb10
@ -0,0 +1,88 @@ |
||||
package com.dxhy.erp.utils; |
||||
|
||||
import cn.hutool.http.HttpRequest; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author ZSC-DXHY |
||||
*/ |
||||
@Slf4j |
||||
public class HttpUtils { |
||||
|
||||
private static final String LOGGER_MSG = "(请求http访问)"; |
||||
|
||||
/** |
||||
* 执行post请求 |
||||
* |
||||
* @param url |
||||
* @param paramMap |
||||
* @return |
||||
* @throws IOException |
||||
*/ |
||||
public static String doPost(String url, Map<String, ?> paramMap) { |
||||
Map<String, Object> requestMap = new HashMap<>(paramMap); |
||||
long startTime = System.currentTimeMillis(); |
||||
String body = HttpRequest.post(url).form(requestMap).timeout(300000).execute().body(); |
||||
long endTime = System.currentTimeMillis(); |
||||
log.debug("{}以Map调用post请求url:{},耗时:{}", LOGGER_MSG, url, endTime - startTime); |
||||
return body; |
||||
} |
||||
|
||||
public static String doPost(String url, String request) { |
||||
long startTime = System.currentTimeMillis(); |
||||
String body = HttpRequest.post(url).body(request).timeout(300000).execute().body(); |
||||
long endTime = System.currentTimeMillis(); |
||||
log.debug("{}以字符串调用post请求url:{},耗时:{}", LOGGER_MSG, url, endTime - startTime); |
||||
return body; |
||||
} |
||||
|
||||
public static String doPostWithHeader(String url, String data, Map<String, String> header) { |
||||
long startTime = System.currentTimeMillis(); |
||||
String body = HttpRequest.post(url).addHeaders(header).body(data).timeout(300000).execute().body(); |
||||
long endTime = System.currentTimeMillis(); |
||||
log.debug("{}带head调用post请求url:{},耗时:{}", LOGGER_MSG, url, endTime - startTime); |
||||
return body; |
||||
} |
||||
|
||||
public static String doPostFormWithHeader(String url, Map<String, ?> paramMap, Map<String, String> header) { |
||||
Map<String, Object> requestMap = new HashMap<>(paramMap); |
||||
long startTime = System.currentTimeMillis(); |
||||
String body = HttpRequest.post(url).addHeaders(header).form(requestMap).timeout(300000).execute().body(); |
||||
long endTime = System.currentTimeMillis(); |
||||
log.debug("{}带head和form调用post请求url:{},耗时:{}", LOGGER_MSG, url, endTime - startTime); |
||||
return body; |
||||
} |
||||
|
||||
public static String doGetWithHeader(String url, Map<String, String> header) { |
||||
long startTime = System.currentTimeMillis(); |
||||
String body = HttpRequest.get(url).addHeaders(header).timeout(300000).execute().body(); |
||||
long endTime = System.currentTimeMillis(); |
||||
log.debug("{}带head调用get请求url:{},耗时:{}", LOGGER_MSG, url, endTime - startTime); |
||||
return body; |
||||
} |
||||
|
||||
public static String doGet(String url, String request) { |
||||
long startTime = System.currentTimeMillis(); |
||||
String body = HttpRequest.get(url).body(request).timeout(300000).execute().body(); |
||||
long endTime = System.currentTimeMillis(); |
||||
log.debug("{}以字符串调用get请求url:{},耗时:{}", LOGGER_MSG, url, endTime - startTime); |
||||
return body; |
||||
} |
||||
|
||||
//请求山能PO
|
||||
public static String sendPo(String url, String request,String userName,String password) { |
||||
long startTime = System.currentTimeMillis(); |
||||
HttpRequest httpRequest = new HttpRequest(url); |
||||
httpRequest.basicAuth(userName,password); |
||||
String body = httpRequest.body(request).timeout(300000).execute().body(); |
||||
long endTime = System.currentTimeMillis(); |
||||
log.debug("{}以字符串调用post请求url:{},耗时:{}", LOGGER_MSG, url, endTime - startTime); |
||||
return body; |
||||
} |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue