Android设置请求头

 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             }   

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。