81,094
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
List<String> urls=new ArrayList();
try {
String html=getHtml("http://119.75.216.20","iso-8859-1");
System.out.println(html);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getHtml(String url,String charset)throws Exception{
HttpClient client = new HttpClient();
if(charset!=null&&!charset.equals("")){
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, charset);
}
HttpMethod method = new GetMethod(url);
int statusCode=client.executeMethod(method);//必须的,否则NullPointerException
return method.getResponseBodyAsString();
}