1 String urlString = "http://api.douban.com/v2/book/search?q=python";
2 try
3 {
4 URI uri = new URI(urlString);
5 HttpGet httpGet = new HttpGet(uri);
6
7
8 // httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
9 // httpGet.setHeader("Accept-Encoding", "gzip, deflate");
10 // httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
11 // httpGet.setHeader("Connection", "keep-alive");
12 // httpGet.setHeader("Host", "api.douban.com");
13 httpGet.setHeader("Accept-Charset", "utf-8");
14 httpGet.setHeader("contentType", "utf-8");
15 httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0");
16
17 HttpResponse response = new DefaultHttpClient().execute(httpGet);
18 String str = EntityUtils.toString(response.getEntity());
19 System.out.println("--->"+str);
20 }
21 catch (Exception e)
22 {
23 e.printStackTrace();
24 }