1String urlstring = "Http://api.douban.com/v2/book/search?q=python"; 2 Try 3 { 4Uri uri =NewURI (urlstring);5HttpGet HttpGet =NewHttpGet (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");Ten //Httpget.setheader ("Accept-language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3"); One //Httpget.setheader ("Connection", "keep-alive"); A //Httpget.setheader ("Host", "api.douban.com"); -Httpget.setheader ("Accept-charset", "Utf-8"); -Httpget.setheader ("ContentType", "Utf-8"); theHttpget.setheader ("User-agent", "mozilla/5.0" (Windows NT 6.1; WOW64; rv:37.0) gecko/20100101 firefox/37.0 "); - -HttpResponse response =Newdefaulthttpclient (). Execute (httpget); -String str =entityutils.tostring (Response.getentity ()); +SYSTEM.OUT.PRINTLN ("--->" +str); - } + Catch(Exception e) A { at E.printstacktrace (); -}
Android Setup Request header