gistfile1.txt public class Crawler { public static void main(String[] args) throws IOException { HttpClient client=new DefaultHttpClient(); HttpGet httpGet=new HttpGet("http://www.baidu.com/"); HttpResponse response=client.execute(httpGet);
public class Crawler { public static void main(String[] args) throws IOException { HttpClient client=new DefaultHttpClient(); HttpGet httpGet=new HttpGet("http://www.baidu.com/"); HttpResponse response=client.execute(httpGet); HttpEntity entity=response.getEntity(); InputStream in=entity.getContent(); byte[] bytes=new byte[1024]; int count; StringBuffer sb = new StringBuffer(); while ((count=in.read(bytes))!=-1) { sb.append(new String(bytes,0,count,"UTF-8")); } System.out.println(sb.toString()); System.out.println("-----------------------"); in.close(); System.out.println(JSON.toJSONString(entity)); } }