|
@@ -1,5 +1,8 @@
|
|
|
package com.caimei.modules.utils;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
@@ -21,8 +24,12 @@ import java.util.Map;
|
|
|
* @author : Charles
|
|
|
* @date : 2021/3/8
|
|
|
*/
|
|
|
-public class RequestUtil {
|
|
|
|
|
|
+public class RequestUtil {
|
|
|
+ /**
|
|
|
+ * 日志对象
|
|
|
+ */
|
|
|
+ protected static Logger logger = LoggerFactory.getLogger(RequestUtil.class);
|
|
|
/**
|
|
|
* 向指定URL发送GET方法的请求
|
|
|
*
|
|
@@ -91,7 +98,7 @@ public class RequestUtil {
|
|
|
// 请求返回的状态
|
|
|
int httpStatus200 = 200;
|
|
|
if (conn.getResponseCode() == httpStatus200) {
|
|
|
-// logger.error("数据发送成功");
|
|
|
+ logger.error("数据发送成功");
|
|
|
// 请求返回的数据
|
|
|
InputStream in = conn.getInputStream();
|
|
|
try {
|
|
@@ -99,18 +106,17 @@ public class RequestUtil {
|
|
|
in.read(responseData);
|
|
|
return new String(responseData, StandardCharsets.UTF_8);
|
|
|
} catch (Exception e) {
|
|
|
-// logger.error("响应数据解析失败");
|
|
|
+ logger.error("响应数据解析失败==="+e);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
} else {
|
|
|
-// logger.error("数据发送失败");
|
|
|
+ logger.error("数据发送失败");
|
|
|
return null;
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -140,7 +146,6 @@ public class RequestUtil {
|
|
|
conn.setRequestProperty("accept", "*/*");
|
|
|
conn.setRequestProperty("connection", "Keep-Alive");
|
|
|
conn.setRequestProperty("Accept-Charset", "utf-8");
|
|
|
- conn.setRequestProperty("Content-Type","application/json");
|
|
|
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
|
|
// 发送POST请求必须设置如下两行
|
|
|
conn.setDoOutput(true);
|