|
@@ -173,8 +173,7 @@ public class MyHttpUtils {
|
|
|
//创建post方式请求对象
|
|
|
HttpPost httpPost = new HttpPost(path);
|
|
|
//创建httpclient对象
|
|
|
- CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
- try {
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
Map<String, Object> resMap = getObjectMap(params, httpPost, httpClient);
|
|
|
if ((int) resMap.get("ReturnCode") == 0) {
|
|
|
return JSONObject.parseObject(resMap.get("Data").toString(), HashMap.class);
|
|
@@ -182,15 +181,9 @@ public class MyHttpUtils {
|
|
|
return null;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
- } finally {
|
|
|
- //释放连接
|
|
|
- try {
|
|
|
- httpClient.close();
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
+ System.out.println(e.getMessage());
|
|
|
}
|
|
|
+ //释放连接
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -201,8 +194,7 @@ public class MyHttpUtils {
|
|
|
//创建post方式请求对象
|
|
|
HttpPost httpPost = new HttpPost(path);
|
|
|
//创建httpclient对象
|
|
|
- CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
- try {
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
Map<String, Object> resMap = getObjectMap(params, httpPost, httpClient);
|
|
|
if ((int) resMap.get("ReturnCode") == 0) {
|
|
|
if (resMap.get("Data") == null) {
|
|
@@ -214,14 +206,8 @@ public class MyHttpUtils {
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
System.out.println(e.getMessage());
|
|
|
- } finally {
|
|
|
- //释放连接
|
|
|
- try {
|
|
|
- httpClient.close();
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
+ //释放连接
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -233,8 +219,7 @@ public class MyHttpUtils {
|
|
|
//创建post方式请求对象
|
|
|
HttpPost httpPost = new HttpPost(path);
|
|
|
//创建httpclient对象
|
|
|
- CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
- try {
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
BasicResponseHandler handler = new BasicResponseHandler();
|
|
|
//设置请求格式
|
|
|
String jsonData = JSONObject.toJSONString(params);
|
|
@@ -247,15 +232,9 @@ public class MyHttpUtils {
|
|
|
Map<String, Object> resMap = JSONObject.parseObject(result, HashMap.class);
|
|
|
return resMap;
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
- } finally {
|
|
|
- //释放连接
|
|
|
- try {
|
|
|
- httpClient.close();
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
+ System.out.println(e.getMessage());
|
|
|
}
|
|
|
+ //释放连接
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -265,8 +244,7 @@ public class MyHttpUtils {
|
|
|
//创建post方式请求对象
|
|
|
HttpDelete httpDelete = new HttpDelete(path);
|
|
|
// 创建HTTP客户端
|
|
|
- CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
- try {
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
// BasicResponseHandler handler = new BasicResponseHandler();
|
|
|
// //设置请求格式
|
|
|
// String jsonData = JSONObject.toJSONString(params);
|
|
@@ -281,15 +259,9 @@ public class MyHttpUtils {
|
|
|
result.put("message", responseBody.get("msg"));
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
- } finally {
|
|
|
- //释放连接
|
|
|
- try {
|
|
|
- httpClient.close();
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
+ System.out.println(e.getMessage());
|
|
|
}
|
|
|
+ //释放连接
|
|
|
return null;
|
|
|
}
|
|
|
|