소스 검색

okhttp返回非200的结果时手动关闭response

648540858 4 년 전
부모
커밋
0c2c87d42c
1개의 변경된 파일7개의 추가작업 그리고 0개의 파일을 삭제
  1. 7 0
      src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java

+ 7 - 0
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java

@@ -55,6 +55,9 @@ public class ZLMRESTfulUtils {
                         if (responseStr != null) {
                             responseJSON = JSON.parseObject(responseStr);
                         }
+                    }else {
+                        response.close();
+                        Objects.requireNonNull(response.body()).close();
                     }
                 } catch (ConnectException e) {
                     logger.error(String.format("连接ZLM失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
@@ -74,6 +77,10 @@ public class ZLMRESTfulUtils {
                             } catch (IOException e) {
                                 logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
                             }
+
+                        }else {
+                            response.close();
+                            Objects.requireNonNull(response.body()).close();
                         }
                     }