{"id":692,"date":"2013-09-12T20:16:36","date_gmt":"2013-09-12T12:16:36","guid":{"rendered":"http:\/\/www.yeetrack.com\/?p=692"},"modified":"2013-09-27T22:36:32","modified_gmt":"2013-09-27T14:36:32","slug":"defaulthttpclient-%e4%bd%bf%e7%94%a8gzipinputstream%e8%a7%a3%e5%8e%8b%e7%bc%a9","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=692","title":{"rendered":"DefaultHttpClient \u4f7f\u7528GZIPInputStream\u89e3\u538b\u7f29"},"content":{"rendered":"<p><meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\" \/><br \/>\nDefaultHttpClient \u4f7f\u7528GZIPInputStream\u89e3\u538b\u7f29<br \/>\n\u5f53\u6d4f\u89c8\u5668\u8bbf\u95ee\u7f51\u7ad9\u65f6\uff0c\u6709\u53ef\u80fd\u6d4f\u89c8\u5668\u8fd4\u56de\u7684\u6d88\u606f\u5934\u4e2d\u5e26\u6709 <strong>Content-Encoding:gzip<\/strong>\uff0c\u8868\u660e\u670d\u52a1\u5668\u8fd4\u56de\u7684\u6d88\u606f\u7ecf\u8fc7gzip\u538b\u7f29\uff0c\u8fd9\u4e48\u505a\u662f\u4e3a\u4e86\u8282\u7701\u6d41\u91cf\uff0c\u6d4f\u89c8\u5668\u62ff\u5230gzip\u538b\u7f29\u540e\u7684http\u5305\uff0c\u5bf9\u5176\u8fdb\u884c\u89e3\u538b\u7f29\uff0c\u518d\u6e32\u67d3\u51fa\u6765\u3002\u5728\u4f7f\u7528apache\u63d0\u4f9b\u7684<strong>DefaultHttpClient<\/strong>\u64cd\u4f5chttp\u8bf7\u6c42\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<strong>GZIPInputStream<\/strong>\u5bf9gzip\u538b\u7f29\u8fc7\u7684\u6570\u636e\u5305\u8fdb\u884c\u89e3\u538b\u7f29\u3002android sdk\u8fdb\u884c\u7f51\u7edc\u7f16\u7a0b\u65f6\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\u3002<!--more-->\u7b80\u5355\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>    DefaultHttpClient httpClient =  new DefaultHttpClient();\n    \/\/dns\u63a2\u6d4b\u6e90ip\n    String[] dnsIps = {\"jsdx\", \"yndx\", \"bjdx\", \"bjlt\", \"sclt\", \"shlt\", \"gg\"};\n\n    for(String ip : dnsIps)\n    {\n        HttpPost post = new HttpPost(\"http:\/\/webscan.360.cn\/tools\/dnsInfo.php\");\n        post.addHeader(\"Referer\", \"http:\/\/webscan.360.cn\/tools\/dnslookup\");\n        post.addHeader(\"X-Requested-With\", \"XMLHttpRequest\");\n        post.addHeader(\"Content-Type\",\"application\/x-www-form-urlencoded; charset=UTF-8\");\n        post.addHeader(\"Accept\", \"*\/*\");\n        post.addHeader(\"Accept-Encoding\", \"gzip, deflate\");\n        post.addHeader(\"Accept-Language\", \"zh-cn,en-us;q=0.7,en;q=0.3\");\n        post.addHeader(\"Pragma\", \"no-cache\");\n        post.addHeader(\"Cache-Control\", \"no-cache\");\n\n        List&lt;BasicNameValuePair&gt; params = new ArrayList&lt;BasicNameValuePair&gt;();\n        params.add(new BasicNameValuePair(\"dns_ip\", ip));\n        params.add(new BasicNameValuePair(\"domain_name\", domain));\n        params.add(new BasicNameValuePair(\"dns_type\", \"A\"));\n        UrlEncodedFormEntity formEntity = null;\n        HttpResponse response = null;\n        String responseHtml = null;\n        try\n        {\n            formEntity = new UrlEncodedFormEntity(params, \"utf-8\");\n            post.setEntity(formEntity);\n            response = httpClient.execute(post);\n            InputStream is= response.getEntity().getContent();\n          is= new GZIPInputStream(is);\n          BufferedReader br = new BufferedReader(new InputStreamReader(is));\n          String line = null;\n          StringBuffer sb = new StringBuffer();\n            while((line = br.readLine())!=null) {\n             sb.append(line);\n            }\n            responseHtml = sb.toString();\n\n        } catch (UnsupportedEncodingException e)\n        {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        } catch (ClientProtocolException e)\n        {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        } catch (IOException e)\n        {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>DefaultHttpClient \u4f7f\u7528GZIPInputStream\u89e3\u538b\u7f29 \u5f53\u6d4f\u89c8\u5668\u8bbf\u95ee\u7f51\u7ad9\u65f6\uff0c\u6709\u53ef\u80fd\u6d4f\u89c8\u5668\u8fd4\u56de\u7684\u6d88\u606f\u5934\u4e2d\u5e26\u6709 Content-Encoding:gzip\uff0c\u8868\u660e\u670d\u52a1\u5668\u8fd4\u56de\u7684\u6d88\u606f\u7ecf\u8fc7g&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[43,8,7,5,16],"class_list":["post-692","post","type-post","status-publish","format-standard","hentry","category-coding","tag-android","tag-java","tag-7","tag-5","tag-16"],"views":5247,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=692"}],"version-history":[{"count":1,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/692\/revisions"}],"predecessor-version":[{"id":693,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/692\/revisions\/693"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}