日期:2014-05-20 浏览次数:20890 次
/**
* a http request with given url
*
* @param strUrl
* the url you want to request
* @return
*/
public static String request(String strUrl) {
strUrl = QuhaoConstant.HTTP_URL + strUrl;
URL url = null;
String result = "";
HttpURLConnection urlConn = null;
InputStreamReader in = null;
try {
url = new URL(strUrl);
urlConn = (HttpURLConnection) url.openConnection();
urlConn.setConnectTimeout(1000 * 20);
in = new InputStreamReader(urlConn.getInputStream());
BufferedReader br = new BufferedReader(in);
String readerLine = null;
while ((readerLine = br.readLine()) != null) {
result += readerLine;
}
in.close();
urlConn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
urlConn.disconnect();
}
return result;
}