public static String getUrlResponse(String url) {
try {
HttpGet get = new HttpGet(url);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
return convertStreamToString(entity.getContent());
} catch (Exception e) {
return null;
}
return null;
}

本文详细介绍了如何使用Java的HttpClient和HttpGet类通过HTTP GET方法获取远程URL的内容,并通过流转换为字符串的过程。涵盖了异常处理及返回结果的处理。
3412

被折叠的 条评论
为什么被折叠?



