ky 5 years ago
parent 485e1d47a9
commit aa3280a473

@ -119,12 +119,12 @@
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!--OkHttp-->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.1</version>
</dependency>
<!-- &lt;!&ndash;OkHttp&ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.squareup.okhttp3</groupId>-->
<!-- <artifactId>okhttp</artifactId>-->
<!-- <version>3.9.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.predic8</groupId>

@ -1,45 +0,0 @@
package com.yhjd.util;
import com.alibaba.fastjson.JSONObject;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
public class OkHttpUtils {
public static JSONObject response(OkHttpClient client, Request request){
// 4 执行请求操作
try {
Response response = client.newCall(request).execute();
System.out.println(response);
if (response.isSuccessful()) {
String string = response.body().string();
System.out.println("返回内容"+string);
JSONObject result = JSONObject.parseObject(string);
return result;
}
return null;
} catch (IOException e) {
throw new RuntimeException("请求微服务失败",e);
}
}
public static String stringResponse(OkHttpClient client, Request request){
// 4 执行请求操作
try {
Response response = client.newCall(request).execute();
System.out.println(response);
if (response.isSuccessful()) {
String string = response.body().string();
return string;
}
return null;
} catch (IOException e) {
throw new RuntimeException("请求微服务失败",e);
}
}
}

@ -1,38 +0,0 @@
package com.yhjd.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* <p>
* Title :
* </p>
* <p>
* Description:
* </p>
* <p>
* Author :
* </p>
* <p>
* Department :
* </p>
* <p> Copyright : © </p>
*/
public class QuietCloseUtils {
private static final Logger logger = LoggerFactory.getLogger(QuietCloseUtils.class);
private QuietCloseUtils() {
}
public static void close(AutoCloseable s) {
if(s != null) {
try {
s.close();
s = null;
} catch (Exception var2) {
logger.error("关闭失败", var2);
}
}
}
}
Loading…
Cancel
Save