public static String getContent(String url) throws Exception{
HttpClient hc = new HttpClient();
HttpMethod hm = new GetMethod(url);
int statusCode = -1;
byte[] result = null;
statusCode = hc.executeMethod(hm);
if(statusCode != HttpStatus.SC_OK)//判断返回
return "";
if(hm.getResponseBody()!=null){//获取页面数据
result = hm.getResponseBody();//hm.getStatusLine()――http状态和请求结果
}
String charset = JsoupUtils.getCharset(url); //通过jsoup获得页面的charset
hm.releaseConnection();
String data = null;
if(result != null)
data = new String(result,charset);//字符编码设置
return data;
}
[代码] 获得字符集
/**
* 获得字符集
*/
public static String getCharset (String siteurl) throws Exception{
URL url = new