例如:
public static String sendGetResult(String url, int timeOut, String charset) { BufferedReader br = null; InputStreamReader isr = null; InputStream is = null; HttpURLConnection huc = null; StringBuffer result = new StringBuffer(""); URL newUrl = null; String line = null; try { newUrl = new URL(url); huc = (HttpURLConnection)newUrl.openConnection(); huc.setRequestMethod("PUT"); if (timeOut > 0) { huc.setConnectTimeout(timeOut); huc.setReadTimeout(timeOut); } int state = huc.getResponseCode(); if ((state > 207) || (state < 200)) return null; int state; is = huc.getInputStream(); isr = charset != null ? new InputStreamReader(is, charset) : new InputStreamReader(is); br = new BufferedReader(isr); while ((line = br.readLine()) != null) { result.append("\r\n"); result.append(line); } String str1 = result.toString().trim(); return str1; } catch (IOException ioe) { return null; } catch (OutOfMemoryError menorException) { System.out.println("发送PUT请求内存溢出,内存占用:" + result.capacity()); System.out.println("本溢出请求地址:" + url); System.gc(); return null; } catch (Exception e) { e.printStackTrace(); System.out.println("发送Put请求异常!" + e.getMessage()); return null; } finally { try { if (is != null) { is.close(); } if (isr != null) { isr.close(); } if (br != null) { br.close(); } if (huc != null) { huc.disconnect()(); } result = null; } catch (Exception e) { System.out.println("发送Put请求时关闭流和对象出错"); } } }