日期:2014-05-17 浏览次数:20802 次
public String getResponse(String urlStr) throws Exception{ HttpURLConnection connection = null;
BufferedReader bufferedReader = null;
try {
// URL请求
URL url = new URL(urlStr);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
// 请求结果取得
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Statics.CHARSET));
String str = null;
StringBuffer sb = new StringBuffer();
while ((str = bufferedReader.readLine()) != null) {
sb.append(str);
}
return sb.toString();
} catch (Exception e) {
// 错误处理
return "";
} finally {
if (bufferedReader != null) {
bufferedReader.close();
bufferedReader = null;
}
if (connection != null) {
connection.disconnect();
connection = null;
}
logger.debug("End");
}
}