日期:2014-05-20 浏览次数:20967 次
String str="http://food.39.net/a/2012322/1995027.html"; HttpClient client = new HttpClient(); GetMethod method = new GetMethod(str); List<Header> headers = new ArrayList<Header>(); headers.add(new Header("Host","food.39.net")); headers.add(new Header("User-Agent","Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0)")); headers.add(new Header("Accept","*/*")); headers.add(new Header("Content-Type","application/x-www-form-urlencoded; charset=UTF-8")); headers.add(new Header("Connection","keep-alive")); client.getHostConfiguration().getParams().setParameter("http.default-headers", headers); try { client.executeMethod(method); System.out.println(method.getResponseBodyAsString()); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }