{"id":785,"date":"2011-05-18T09:37:10","date_gmt":"2011-05-18T00:37:10","guid":{"rendered":"http:\/\/blog.rutake.com\/techmemo\/?p=785"},"modified":"2015-09-03T18:30:16","modified_gmt":"2015-09-03T09:30:16","slug":"785","status":"publish","type":"post","link":"https:\/\/blog.rutake.com\/techmemo\/2011\/05\/18\/785\/","title":{"rendered":"HttpComponents HttpClient \u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9"},"content":{"rendered":"<p>HttpClient\u306f3.0\u307e\u3067\u30684.0\u4ee5\u5f8c\u3067\u30af\u30e9\u30b9\u69cb\u6210\u306a\u3069\u304c\u30ac\u30e9\u30ea\u3068\u5909\u308f\u3063\u305f\u3002<br \/>\n\u65e5\u672c\u8a9e\u306e\u30b5\u30a4\u30c8\u3067\u306f\u307e\u3060\u4f7f\u7528\u4f8b\u304c\u5c11\u306a\u3044\u306e\u3067\u3001\u60c5\u5831\u53ce\u96c6\u306b\u3082\u82e6\u52b4\u3059\u308b\u3002<\/p>\n<p>\u3068\u3044\u3046\u308f\u3051\u3067\u30b7\u30f3\u30d7\u30eb\u306bGET\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3001\u7d50\u679c\u3092\u8868\u793a\u3059\u308b\u3060\u3051\u306e\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u63d0\u4f9b\u3057\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>[JAVA]<br \/>\nimport java.io.IOException;<\/p>\n<p>import org.apache.http.HttpEntity;<br \/>\nimport org.apache.http.HttpResponse;<br \/>\nimport org.apache.http.client.ClientProtocolException;<br \/>\nimport org.apache.http.client.methods.HttpGet;<br \/>\nimport org.apache.http.impl.client.DefaultHttpClient;<br \/>\nimport org.apache.http.util.EntityUtils;<\/p>\n<p>public class SimpleHttpClient {<\/p>\n<p>\t\/**<br \/>\n\t * @param args<br \/>\n\t * @throws IOException<br \/>\n\t * @throws ClientProtocolException<br \/>\n\t *\/<br \/>\n\tpublic static void main(String[] args) throws ClientProtocolException, IOException {<br \/>\n\t\t\/\/ TODO Auto-generated method stub<br \/>\n\t\tDefaultHttpClient client = new DefaultHttpClient();<br \/>\n\t\tHttpGet httpGet = new HttpGet(&#8220;http:\/\/www.rutake.com\/&#8221;);<br \/>\n\t\tHttpResponse httpResponse = client.execute(httpGet);<\/p>\n<p>\t\tSystem.out.println(httpResponse.getStatusLine());<br \/>\n\t\tHttpEntity entity = httpResponse.getEntity();<br \/>\n\t\t\/\/ ContentType\u8868\u793a<br \/>\n\t\tSystem.out.println(entity.getContentType());<br \/>\n\t\t\/\/ ContentEncoding\u8868\u793a<br \/>\n\t\tSystem.out.println(entity.getContentEncoding());<br \/>\n\t\t\/\/ Content-Length\u8868\u793a<br \/>\n\t\tSystem.out.println(entity.getContentLength());<\/p>\n<p>\t\t\/\/ \u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u898b\u308c\u308b\u306e\u306f\u4e00\u56de\u304d\u308a(\u4e8c\u56de\u4ee5\u4e0a\u547c\u3076\u306a\u3089String\u5909\u6570\u306b\u5165\u308c\u3066\u304a\u304f)<br \/>\n\t\tSystem.out.println(EntityUtils.toString(entity));<\/p>\n<p>\t\t\/\/ \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u3092\u30af\u30ed\u30fc\u30ba<br \/>\n\t\tentity.consumeContent();<\/p>\n<p>\t\t\/\/ http\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306f\u8907\u6570\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u6295\u3052\u3089\u308c\u308b\u3001\u6700\u5f8c\u306f\u7d42\u4e86<br \/>\n\t\tclient.getConnectionManager().shutdown();<br \/>\n\t}<\/p>\n<p>}<br \/>\n[\/JAVA]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HttpClient\u306f3.0\u307e\u3067\u30684.0\u4ee5\u5f8c\u3067\u30af\u30e9\u30b9\u69cb\u6210\u306a\u3069\u304c\u30ac\u30e9\u30ea\u3068\u5909\u308f\u3063\u305f\u3002 &hellip; <a href=\"https:\/\/blog.rutake.com\/techmemo\/2011\/05\/18\/785\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[138,137],"_links":{"self":[{"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/posts\/785"}],"collection":[{"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/comments?post=785"}],"version-history":[{"count":3,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/posts\/785\/revisions"}],"predecessor-version":[{"id":2175,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/posts\/785\/revisions\/2175"}],"wp:attachment":[{"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/media?parent=785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/categories?post=785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.rutake.com\/techmemo\/wp-json\/wp\/v2\/tags?post=785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}