Commit aed4dbe191bcf4e5529a82801ac33c65d791136a
1 parent
e197429223
Exists in
master
and in
6 other branches
update code
Showing 1 changed file with 7 additions and 1 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/HttpRequest.java
View file @
aed4dbe
... | ... | @@ -136,6 +136,7 @@ |
136 | 136 | public static String sendGet(String url, Map<String,String> params,Map<String,String> headers) { |
137 | 137 | String result = ""; |
138 | 138 | BufferedReader in = null; |
139 | + HttpURLConnection connection = null; | |
139 | 140 | StringBuffer sb = new StringBuffer(); |
140 | 141 | if(params!=null && !params.isEmpty()) { |
141 | 142 | Iterator<String> keys = params.keySet().iterator(); |
... | ... | @@ -151,7 +152,7 @@ |
151 | 152 | |
152 | 153 | URL realUrl = new URL(url +sb); |
153 | 154 | // 打开和URL之间的连接 |
154 | - URLConnection connection = realUrl.openConnection(); | |
155 | + connection = (HttpURLConnection)realUrl.openConnection(); | |
155 | 156 | // 设置通用的请求属性 |
156 | 157 | connection.setRequestProperty("accept", "*/*"); |
157 | 158 | connection.setRequestProperty("Method","GET"); |
... | ... | @@ -179,6 +180,7 @@ |
179 | 180 | while ((line = in.readLine()) != null) { |
180 | 181 | result += line; |
181 | 182 | } |
183 | + | |
182 | 184 | } catch (Exception e) { |
183 | 185 | System.out.println("发送GET请求出现异常!" + e); |
184 | 186 | e.printStackTrace(); |
... | ... | @@ -188,6 +190,10 @@ |
188 | 190 | try { |
189 | 191 | if (in != null) { |
190 | 192 | in.close(); |
193 | + } | |
194 | + if (connection != null) | |
195 | + { | |
196 | + connection.disconnect(); | |
191 | 197 | } |
192 | 198 | } catch (Exception e2) { |
193 | 199 | e2.printStackTrace(); |