{"id":597,"date":"2013-06-23T13:04:49","date_gmt":"2013-06-23T05:04:49","guid":{"rendered":"http:\/\/www.yeetrack.com\/?p=597"},"modified":"2013-09-27T22:36:37","modified_gmt":"2013-09-27T14:36:37","slug":"httpclient-%e6%95%99%e7%a8%8b-%e4%b8%80","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=597","title":{"rendered":"HttpClient \u6559\u7a0b (\u4e00)"},"content":{"rendered":"<div id=\"topics\">\n<div class=\"post\">\n<h1 class=\"postTitle\"><a class=\"postTitle2\" id=\"cb_post_title_url\" href=\"http:\/\/www.cnblogs.com\/loveyakamoz\/archive\/2011\/07\/21\/2112804.html\">\u524d\u8a00<\/a><\/h1>\n<div class=\"postBody\">\n<div id=\"cnblogs_post_body\">\n<div class=\"inherit_c wrap_text\" style=\"font-family: Verdana, Arial, Tahoma, sans-serif; word-wrap: break-word; word-break: break-all; font-size: 9.5pt; line-height: normal; padding-top: 4px; padding-right: 0px; padding-bottom: 4px; padding-left: 0px;\">\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8d85\u6587\u672c\u4f20\u8f93\u534f\u8bae\uff08HTTP\uff09\u4e5f\u8bb8\u662f\u5f53\u4eca\u4e92\u8054\u7f51\u4e0a\u4f7f\u7528\u7684\u6700\u91cd\u8981\u7684\u534f\u8bae\u4e86\u3002Web\u670d\u52a1\uff0c\u6709\u7f51\u7edc\u529f\u80fd\u7684\u8bbe\u5907\u548c\u7f51\u7edc\u8ba1\u7b97\u7684\u53d1\u5c55\uff0c\u90fd\u6301\u7eed\u6269\u5c55\u4e86HTTP\u534f\u8bae\u7684\u89d2\u8272\uff0c\u8d85\u8d8a\u4e86\u7528\u6237\u4f7f\u7528\u7684Web\u6d4f\u89c8\u5668\u8303\u7574\uff0c\u540c\u65f6\uff0c\u4e5f\u589e\u52a0\u4e86\u9700\u8981HTTP\u534f\u8bae\u652f\u6301\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u6570\u91cf\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5c3d\u7ba1java.net\u5305\u63d0\u4f9b\u4e86\u57fa\u672c\u901a\u8fc7HTTP\u8bbf\u95ee\u8d44\u6e90\u7684\u529f\u80fd\uff0c\u4f46\u5b83\u6ca1\u6709\u63d0\u4f9b\u5168\u9762\u7684\u7075\u6d3b\u6027\u548c\u5176\u5b83\u5f88\u591a\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u7684\u529f\u80fd\u3002HttpClient\u5c31\u662f\u5bfb\u6c42\u5f25\u8865\u8fd9\u9879\u7a7a\u767d\u7684\u7ec4\u4ef6\uff0c\u901a\u8fc7\u63d0\u4f9b\u4e00\u4e2a\u6709\u6548\u7684\uff0c\u4fdd\u6301\u66f4\u65b0\u7684\uff0c\u529f\u80fd\u4e30\u5bcc\u7684\u8f6f\u4ef6\u5305\u6765\u5b9e\u73b0\u5ba2\u6237\u7aef\u6700\u65b0\u7684HTTP\u6807\u51c6\u548c\u5efa\u8bae\u3002<!--more--><\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u4e3a\u6269\u5c55\u800c\u8bbe\u8ba1\uff0c\u540c\u65f6\u4e3a\u57fa\u672c\u7684HTTP\u534f\u8bae\u63d0\u4f9b\u5f3a\u5927\u7684\u652f\u6301\uff0cHttpClient\u7ec4\u4ef6\u4e5f\u8bb8\u5c31\u662f\u6784\u5efaHTTP\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\uff0c\u6bd4\u5982web\u6d4f\u89c8\u5668\uff0cweb\u670d\u52a1\u7aef\uff0c\u5229\u7528\u6216\u6269\u5c55HTTP\u534f\u8bae\u8fdb\u884c\u5206\u5e03\u5f0f\u901a\u4fe1\u7684\u7cfb\u7edf\u7684\u5f00\u53d1\u4eba\u5458\u7684\u5173\u6ce8\u70b9\u3002<\/p>\n<h3 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1. HttpClient\u7684\u8303\u56f4<\/h3>\n<ul style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\u57fa\u4e8eHttpCore[http:\/\/hc.apache.org\/httpcomponents-core\/index.html]\u7684\u5ba2\u6237\u7aefHTTP\u8fd0\u8f93\u5b9e\u73b0\u5e93<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\u57fa\u4e8e\u7ecf\u5178\uff08\u963b\u585e\uff09I\/O<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\u5185\u5bb9\u65e0\u5173<\/li>\n<\/ul>\n<h3 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">2. \u4ec0\u4e48\u662fHttpClient\u4e0d\u80fd\u505a\u7684<\/h3>\n<ul style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">HttpClient\u4e0d\u662f\u4e00\u4e2a\u6d4f\u89c8\u5668\u3002\u5b83\u662f\u4e00\u4e2a\u5ba2\u6237\u7aef\u7684HTTP\u901a\u4fe1\u5b9e\u73b0\u5e93\u3002HttpClient\u7684\u76ee\u6807\u662f\u53d1\u9001\u548c\u63a5\u6536HTTP\u62a5\u6587\u3002HttpClient\u4e0d\u4f1a\u53bb\u7f13\u5b58\u5185\u5bb9\uff0c\u6267\u884c\u5d4c\u5165\u5728HTML\u9875\u9762\u4e2d\u7684javascript\u4ee3\u7801\uff0c\u731c\u6d4b\u5185\u5bb9\u7c7b\u578b\uff0c\u91cd\u65b0\u683c\u5f0f\u5316\u8bf7\u6c42\/\u91cd\u5b9a\u5411URI\uff0c\u6216\u8005\u5176\u5b83\u548cHTTP\u8fd0\u8f93\u65e0\u5173\u7684\u529f\u80fd\u3002<\/li>\n<\/ul>\n<h2 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\u7b2c\u4e00\u7ae0 \u57fa\u7840<\/h2>\n<h3 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1 \u6267\u884c\u8bf7\u6c42<\/h3>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient\u6700\u91cd\u8981\u7684\u529f\u80fd\u662f\u6267\u884cHTTP\u65b9\u6cd5\u3002\u4e00\u4e2aHTTP\u65b9\u6cd5\u7684\u6267\u884c\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2aHTTP\u8bf7\u6c42\/HTTP\u54cd\u5e94\u4ea4\u6362\uff0c\u901a\u5e38\u7531HttpClient\u7684\u5185\u90e8\u6765\u5904\u7406\u3002\u800c\u671f\u671b\u7528\u6237\u63d0\u4f9b\u4e00\u4e2a\u8981\u6267\u884c\u7684\u8bf7\u6c42\u5bf9\u8c61\uff0c\u800cHttpClient\u671f\u671b\u4f20\u8f93\u8bf7\u6c42\u5230\u76ee\u6807\u670d\u52a1\u5668\u5e76\u8fd4\u56de\u5bf9\u5e94\u7684\u54cd\u5e94\u5bf9\u8c61\uff0c\u6216\u8005\u5f53\u6267\u884c\u4e0d\u6210\u529f\u65f6\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5f88\u81ea\u7136\u5730\uff0cHttpClient API\u7684\u4e3b\u8981\u5207\u5165\u70b9\u5c31\u662f\u5b9a\u4e49\u63cf\u8ff0\u4e0a\u8ff0\u89c4\u7ea6\u7684HttpClient\u63a5\u53e3\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8fd9\u91cc\u6709\u4e00\u4e2a\u5f88\u7b80\u5355\u7684\u8bf7\u6c42\u6267\u884c\u8fc7\u7a0b\u7684\u793a\u4f8b\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient httpclient = new DefaultHttpClient();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpGet httpget = new HttpGet(\"http:\/\/localhost\/\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpResponse response = httpclient.execute(httpget);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpEntity entity = response.getEntity();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">if (entity != null) {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">InputStream instream = entity.getContent();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">int l;<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">byte[] tmp = new byte[2048];<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">while ((l = instream.read(tmp)) != -1) {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<\/blockquote>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.1 HTTP\u8bf7\u6c42<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u6240\u6709HTTP\u8bf7\u6c42\u6709\u4e00\u4e2a\u7ec4\u5408\u4e86\u65b9\u6cd5\u540d\uff0c\u8bf7\u6c42URI\u548cHTTP\u534f\u8bae\u7248\u672c\u7684\u8bf7\u6c42\u884c\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient\u652f\u6301\u6240\u6709\u5b9a\u4e49\u5728HTTP\/1.1\u7248\u672c\u4e2d\u7684HTTP\u65b9\u6cd5\uff1aGET\uff0cHEAD\uff0cPOST\uff0cPUT\uff0cDELETE\uff0cTRACE\u548cOPTIONS\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u65b9\u6cd5\u7c7b\u578b\u90fd\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u7c7b\uff1aHttpGet\uff0cHttpHead\uff0cHttpPost\uff0cHttpPut\uff0cHttpDelete\uff0cHttpTrace\u548cHttpOptions\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8bf7\u6c42\u7684URI\u662f\u7edf\u4e00\u8d44\u6e90\u5b9a\u4f4d\u7b26\uff0c\u5b83\u6807\u8bc6\u4e86\u5e94\u7528\u4e8e\u54ea\u4e2a\u8bf7\u6c42\u4e4b\u4e0a\u7684\u8d44\u6e90\u3002HTTP\u8bf7\u6c42URI\u5305\u542b\u4e00\u4e2a\u534f\u8bae\u6a21\u5f0f\uff0c\u4e3b\u673a\u540d\u79f0\uff0c\u53ef\u9009\u7684\u7aef\u53e3\uff0c\u8d44\u6e90\u8def\u5f84\uff0c\u53ef\u9009\u7684\u67e5\u8be2\u548c\u53ef\u9009\u7684\u7247\u6bb5\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpGet httpget = new HttpGet(<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\"http:\/\/www.google.com\/search?hl=en&amp;q=httpclient&amp;btnG=Google+Search&amp;aq=f&amp;oq=\");<\/div>\n<\/blockquote>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient\u63d0\u4f9b\u5f88\u591a\u5de5\u5177\u65b9\u6cd5\u6765\u7b80\u5316\u521b\u5efa\u548c\u4fee\u6539\u6267\u884cURI\u3002<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">URI\u4e5f\u53ef\u4ee5\u7f16\u7a0b\u6765\u62fc\u88c5\uff1a<\/div>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">URI uri = URIUtils.createURI(\"http\", \"www.google.com\", -1, \"\/search\",<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\"q=httpclient&amp;btnG=Google+Search&amp;aq=f&amp;oq=\", null);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpGet httpget = new HttpGet(uri);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(httpget.getURI());<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">http:\/\/www.google.com\/search?q=httpclient&btnG=Google+Search&aq=f&oq=<\/p>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u67e5\u8be2\u5b57\u7b26\u4e32\u4e5f\u53ef\u4ee5\u4ece\u72ec\u7acb\u7684\u53c2\u6570\u4e2d\u6765\u751f\u6210\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">List&lt;NameValuePair&gt; qparams = new ArrayList&lt;NameValuePair&gt;();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">qparams.add(new BasicNameValuePair(\"q\", \"httpclient\"));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">qparams.add(new BasicNameValuePair(\"btnG\", \"Google Search\"));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">qparams.add(new BasicNameValuePair(\"aq\", \"f\"));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">qparams.add(new BasicNameValuePair(\"oq\", null));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">URI uri = URIUtils.createURI(\"http\", \"www.google.com\", -1, \"\/search\",<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">URLEncodedUtils.format(qparams, \"UTF-8\"), null);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpGet httpget = new HttpGet(uri);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(httpget.getURI());<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">http:\/\/www.google.com\/search?q=httpclient&btnG=Google+Search&aq=f&oq=<\/p>\n<\/blockquote>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.2 HTTP\u54cd\u5e94<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HTTP\u54cd\u5e94\u662f\u7531\u670d\u52a1\u5668\u5728\u63a5\u6536\u548c\u89e3\u91ca\u8bf7\u6c42\u62a5\u6587\u4e4b\u540e\u8fd4\u56de\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u7684\u62a5\u6587\u3002\u54cd\u5e94\u62a5\u6587\u7684\u7b2c\u4e00\u884c\u5305\u542b\u4e86\u534f\u8bae\u7248\u672c\uff0c\u4e4b\u540e\u662f\u6570\u5b57\u72b6\u6001\u7801\u548c\u76f8\u5173\u8054\u7684\u6587\u672c\u6bb5\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpStatus.SC_OK, \"OK\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(response.getProtocolVersion());<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(response.getStatusLine().getStatusCode());<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(response.getStatusLine().getReasonPhrase());<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(response.getStatusLine().toString());<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HTTP\/1.1<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">200<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">OK<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HTTP\/1.1 200 OK<\/div>\n<\/blockquote>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.3 \u5904\u7406\u62a5\u6587\u5934\u90e8<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u4e00\u4e2aHTTP\u62a5\u6587\u53ef\u4ee5\u5305\u542b\u5f88\u591a\u63cf\u8ff0\u5982\u5185\u5bb9\u957f\u5ea6\uff0c\u5185\u5bb9\u7c7b\u578b\u7b49\u4fe1\u606f\u5c5e\u6027\u7684\u5934\u90e8\u4fe1\u606f\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient\u63d0\u4f9b\u83b7\u53d6\uff0c\u6dfb\u52a0\uff0c\u79fb\u9664\u548c\u679a\u4e3e\u5934\u90e8\u4fe1\u606f\u7684\u65b9\u6cd5\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpStatus.SC_OK, \"OK\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">response.addHeader(\"Set-Cookie\",<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\"c1=a; path=\/; domain=localhost\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">response.addHeader(\"Set-Cookie\",<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\"c2=b; path=\\\"\/\\\", c3=c; domain=\\\"localhost\\\"\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Header h1 = response.getFirstHeader(\"Set-Cookie\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(h1);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Header h2 = response.getLastHeader(\"Set-Cookie\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(h2);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Header[] hs = response.getHeaders(\"Set-Cookie\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(hs.length);<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Set-Cookie: c1=a; path=\/; domain=localhost<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Set-Cookie: c2=b; path=\"\/\", c3=c; domain=\"localhost\"<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u83b7\u5f97\u7ed9\u5b9a\u7c7b\u578b\u7684\u6240\u6709\u5934\u90e8\u4fe1\u606f\u6700\u6709\u6548\u7684\u65b9\u5f0f\u662f\u4f7f\u7528HeaderIterator\u63a5\u53e3\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpStatus.SC_OK, \"OK\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">response.addHeader(\"Set-Cookie\",<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\"c1=a; path=\/; domain=localhost\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">response.addHeader(\"Set-Cookie\",<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\"c2=b; path=\\\"\/\\\", c3=c; domain=\\\"localhost\\\"\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HeaderIterator it = response.headerIterator(\"Set-Cookie\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">while (it.hasNext()) {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(it.next());<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Set-Cookie: c1=a; path=\/; domain=localhost<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Set-Cookie: c2=b; path=\"\/\", c3=c; domain=\"localhost\"<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5b83\u4e5f\u63d0\u4f9b\u89e3\u6790HTTP\u62a5\u6587\u5230\u72ec\u7acb\u5934\u90e8\u4fe1\u606f\u5143\u7d20\u7684\u65b9\u6cd5\u65b9\u6cd5\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpStatus.SC_OK, \"OK\");<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>response.addHeader(\"Set-Cookie\",<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>\"c1=a; path=\/; domain=localhost\");<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>response.addHeader(\"Set-Cookie\",<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>\"c2=b; path=\\\"\/\\\", c3=c; domain=\\\"localhost\\\"\");<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HeaderElementIterator it = new BasicHeaderElementIterator(<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>response.headerIterator(\"Set-Cookie\"));<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>while (it.hasNext()) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HeaderElement elem = it.nextElement();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>System.out.println(elem.getName() + \" = \" + elem.getValue());<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>NameValuePair[] params = elem.getParameters();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>for (int i = 0; i &lt; params.length; i++) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>System.out.println(\" \" + params[i]);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<\/div>\n<\/blockquote>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">c1 = a<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">path=\/<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">domain=localhost<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">c2 = b<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">path=\/<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">c3 = c<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">domain=localhost<\/div>\n<\/blockquote>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.4 HTTP\u5b9e\u4f53<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HTTP\u62a5\u6587\u53ef\u4ee5\u643a\u5e26\u548c\u8bf7\u6c42\u6216\u54cd\u5e94\u76f8\u5173\u7684\u5185\u5bb9\u5b9e\u4f53\u3002\u5b9e\u4f53\u53ef\u4ee5\u5728\u4e00\u4e9b\u8bf7\u6c42\u548c\u54cd\u5e94\u4e2d\u627e\u5230\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e5f\u662f\u53ef\u9009\u7684\u3002\u4f7f\u7528\u4e86\u5b9e\u4f53\u7684\u8bf7\u6c42\u88ab\u79f0\u4e3a\u5c01\u95ed\u5b9e\u4f53\u8bf7\u6c42\u3002HTTP\u89c4\u8303\u5b9a\u4e49\u4e86\u4e24\u79cd\u5c01\u95ed\u5b9e\u4f53\u7684\u65b9\u6cd5\uff1aPOST\u548cPUT\u3002\u54cd\u5e94\u901a\u5e38\u671f\u671b\u5305\u542b\u4e00\u4e2a\u5185\u5bb9\u5b9e\u4f53\u3002\u8fd9\u4e2a\u89c4\u5219\u4e5f\u6709\u7279\u4f8b\uff0c\u6bd4\u5982HEAD\u65b9\u6cd5\u7684\u54cd\u5e94\u548c204 No Content\uff0c304 Not Modified\u548c205 Reset Content\u54cd\u5e94\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient\u6839\u636e\u5176\u5185\u5bb9\u51fa\u81ea\u4f55\u5904\u533a\u5206\u4e09\u79cd\u7c7b\u578b\u7684\u5b9e\u4f53\uff1a<\/p>\n<ul style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">streamed\u6d41\u5f0f\uff1a\u5185\u5bb9\u4ece\u6d41\u4e2d\u83b7\u5f97\uff0c\u6216\u8005\u5728\u8fd0\u884c\u4e2d\u4ea7\u751f\u3002\u7279\u522b\u662f\u8fd9\u79cd\u5206\u7c7b\u5305\u542b\u4eceHTTP\u54cd\u5e94\u4e2d\u83b7\u53d6\u7684\u5b9e\u4f53\u3002\u6d41\u5f0f\u5b9e\u4f53\u662f\u4e0d\u53ef\u91cd\u590d\u751f\u6210\u7684\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">self-contained\u81ea\u6211\u5305\u542b\u5f0f\uff1a\u5185\u5bb9\u5728\u5185\u5b58\u4e2d\u6216\u901a\u8fc7\u72ec\u7acb\u7684\u8fde\u63a5\u6216\u5176\u5b83\u5b9e\u4f53\u4e2d\u83b7\u5f97\u3002\u81ea\u6211\u5305\u542b\u5f0f\u7684\u5b9e\u4f53\u662f\u53ef\u4ee5\u91cd\u590d\u751f\u6210\u7684\u3002\u8fd9\u79cd\u7c7b\u578b\u7684\u5b9e\u4f53\u4f1a\u7ecf\u5e38\u7528\u4e8e\u5c01\u95edHTTP\u8bf7\u6c42\u7684\u5b9e\u4f53\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">wrapping\u5305\u88c5\u5f0f\uff1a\u5185\u5bb9\u4ece\u53e6\u5916\u4e00\u4e2a\u5b9e\u4f53\u4e2d\u83b7\u5f97\u3002<\/li>\n<\/ul>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5f53\u4ece\u4e00\u4e2aHTTP\u54cd\u5e94\u4e2d\u83b7\u53d6\u6d41\u5f0f\u5185\u5bb9\u65f6\uff0c\u8fd9\u4e2a\u533a\u522b\u5bf9\u4e8e\u8fde\u63a5\u7ba1\u7406\u5f88\u91cd\u8981\u3002\u5bf9\u4e8e\u7531\u5e94\u7528\u7a0b\u5e8f\u521b\u5efa\u800c\u4e14\u53ea\u4f7f\u7528HttpClient\u53d1\u9001\u7684\u8bf7\u6c42\u5b9e\u4f53\uff0c\u6d41\u5f0f\u548c\u81ea\u6211\u5305\u542b\u5f0f\u7684\u4e0d\u540c\u5c31\u4e0d\u90a3\u4e48\u91cd\u8981\u4e86\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5efa\u8bae\u8003\u8651\u5982\u6d41\u5f0f\u8fd9\u79cd\u4e0d\u80fd\u91cd\u590d\u7684\u5b9e\u4f53\uff0c\u548c\u53ef\u4ee5\u91cd\u590d\u7684\u81ea\u6211\u5305\u542b\u5f0f\u5b9e\u4f53\u3002<\/p>\n<h5 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.4.1 \u91cd\u590d\u5b9e\u4f53<\/h5>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5b9e\u4f53\u53ef\u4ee5\u91cd\u590d\uff0c\u610f\u5473\u7740\u5b83\u7684\u5185\u5bb9\u53ef\u4ee5\u88ab\u591a\u6b21\u8bfb\u53d6\u3002\u8fd9\u5c31\u4ec5\u4ec5\u662f\u81ea\u6211\u5305\u542b\u5f0f\u7684\u5b9e\u4f53\u4e86\uff08\u50cfByteArrayEntity\u6216StringEntity\uff09\u3002<\/p>\n<h5 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.4.2 \u4f7f\u7528HTTP\u5b9e\u4f53<\/h5>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u56e0\u4e3a\u4e00\u4e2a\u5b9e\u4f53\u65e2\u53ef\u4ee5\u4ee3\u8868\u4e8c\u8fdb\u5236\u5185\u5bb9\u53c8\u53ef\u4ee5\u4ee3\u8868\u5b57\u7b26\u5185\u5bb9\uff0c\u5b83\u4e5f\u652f\u6301\u5b57\u7b26\u7f16\u7801\uff08\u652f\u6301\u540e\u8005\u4e5f\u5c31\u662f\u5b57\u7b26\u5185\u5bb9\uff09\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5b9e\u4f53\u662f\u5f53\u4f7f\u7528\u5c01\u95ed\u5185\u5bb9\u6267\u884c\u8bf7\u6c42\uff0c\u6216\u5f53\u8bf7\u6c42\u5df2\u7ecf\u6210\u529f\u6267\u884c\uff0c\u6216\u5f53\u54cd\u5e94\u4f53\u7ed3\u679c\u53d1\u529f\u5230\u5ba2\u6237\u7aef\u65f6\u521b\u5efa\u7684\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8981\u4ece\u5b9e\u4f53\u4e2d\u8bfb\u53d6\u5185\u5bb9\uff0c\u53ef\u4ee5\u901a\u8fc7HttpEntity#getContent()\u65b9\u6cd5\u4ece\u8f93\u5165\u6d41\u4e2d\u83b7\u53d6\uff0c\u8fd9\u4f1a\u8fd4\u56de\u4e00\u4e2ajava.io.InputStream\u5bf9\u8c61\uff0c\u6216\u8005\u63d0\u4f9b\u4e00\u4e2a\u8f93\u51fa\u6d41\u5230HttpEntity#writeTo(OutputStream)\u65b9\u6cd5\u4e2d\uff0c\u8fd9\u4f1a\u4e00\u6b21\u8fd4\u56de\u6240\u6709\u5199\u5165\u5230\u7ed9\u5b9a\u6d41\u4e2d\u7684\u5185\u5bb9\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5f53\u5b9e\u4f53\u901a\u8fc7\u4e00\u4e2a\u6536\u5230\u7684\u62a5\u6587\u83b7\u53d6\u65f6\uff0cHttpEntity#getContentType()\u65b9\u6cd5\u548cHttpEntity#getContentLength()\u65b9\u6cd5\u53ef\u4ee5\u7528\u6765\u8bfb\u53d6\u901a\u7528\u7684\u5143\u6570\u636e\uff0c\u5982Content-Type\u548cContent-Length\u5934\u90e8\u4fe1\u606f\uff08\u5982\u679c\u5b83\u4eec\u662f\u53ef\u7528\u7684\uff09\u3002\u56e0\u4e3a\u5934\u90e8\u4fe1\u606fContent-Type\u53ef\u4ee5\u5305\u542b\u5bf9\u6587\u672cMIME\u7c7b\u578b\u7684\u5b57\u7b26\u7f16\u7801\uff0c\u6bd4\u5982text\/plain\u6216text\/html\uff0cHttpEntity#getContentEncoding()\u65b9\u6cd5\u7528\u6765\u8bfb\u53d6\u8fd9\u4e2a\u4fe1\u606f\u3002\u5982\u679c\u5934\u90e8\u4fe1\u606f\u4e0d\u53ef\u7528\uff0c\u90a3\u4e48\u5c31\u8fd4\u56de\u957f\u5ea6-1\uff0c\u800c\u5bf9\u4e8e\u5185\u5bb9\u7c7b\u578b\u8fd4\u56deNULL\u3002\u5982\u679c\u5934\u90e8\u4fe1\u606fContent-Type\u662f\u53ef\u7528\u7684\uff0c\u90a3\u4e48\u5c31\u4f1a\u8fd4\u56de\u4e00\u4e2aHeader\u5bf9\u8c61\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5f53\u4e3a\u4e00\u4e2a\u4f20\u51fa\u62a5\u6587\u521b\u5efa\u5b9e\u4f53\u65f6\uff0c\u8fd9\u4e2a\u5143\u6570\u636e\u4e0d\u5f97\u4e0d\u901a\u8fc7\u5b9e\u4f53\u521b\u5efa\u5668\u6765\u63d0\u4f9b\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">StringEntity myEntity = new StringEntity(\"important message\",<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\"UTF-8\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(myEntity.getContentType());<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(myEntity.getContentLength());<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(EntityUtils.getContentCharSet(myEntity));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(EntityUtils.toString(myEntity));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(EntityUtils.toByteArray(myEntity).length);<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a<\/p>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Content-Type: text\/plain; charset=UTF-8<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">17<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">UTF-8<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">important message<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">17<\/div>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.5 \u786e\u4fdd\u4f4e\u7ea7\u522b\u8d44\u6e90\u91ca\u653e<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5f53\u5b8c\u6210\u4e00\u4e2a\u54cd\u5e94\u5b9e\u4f53\uff0c\u90a3\u4e48\u4fdd\u8bc1\u6240\u6709\u5b9e\u4f53\u5185\u5bb9\u5df2\u7ecf\u88ab\u5b8c\u5168\u6d88\u8017\u662f\u5f88\u91cd\u8981\u7684\uff0c\u6240\u4ee5\u8fde\u63a5\u53ef\u4ee5\u5b89\u5168\u7684\u653e\u56de\u5230\u8fde\u63a5\u6c60\u4e2d\uff0c\u800c\u4e14\u53ef\u4ee5\u901a\u8fc7\u8fde\u63a5\u7ba1\u7406\u5668\u5bf9\u540e\u7eed\u7684\u8bf7\u6c42\u91cd\u7528\u8fde\u63a5\u3002\u5904\u7406\u8fd9\u4e2a\u64cd\u4f5c\u7684\u6700\u65b9\u4fbf\u7684\u65b9\u6cd5\u662f\u8c03\u7528HttpEntity#consumeContent()\u65b9\u6cd5\u6765\u6d88\u8017\u6d41\u4e2d\u7684\u4efb\u610f\u53ef\u7528\u5185\u5bb9\u3002HttpClient\u63a2\u6d4b\u5230\u5185\u5bb9\u6d41\u5c3e\u90e8\u5df2\u7ecf\u5230\u8fbe\u540e\uff0c\u4f1a\u7acb\u5373\u4f1a\u81ea\u52a8\u91ca\u653e\u4f4e\u5c42\u8fde\u63a5\uff0c\u5e76\u653e\u56de\u5230\u8fde\u63a5\u7ba1\u7406\u5668\u3002HttpEntity#consumeContent()\u65b9\u6cd5\u8c03\u7528\u591a\u6b21\u4e5f\u662f\u5b89\u5168\u7684\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u4e5f\u53ef\u80fd\u4f1a\u6709\u7279\u6b8a\u60c5\u51b5\uff0c\u5f53\u6574\u4e2a\u54cd\u5e94\u5185\u5bb9\u7684\u4e00\u5c0f\u90e8\u5206\u9700\u8981\u83b7\u53d6\uff0c\u6d88\u8017\u5269\u4f59\u5185\u5bb9\u800c\u635f\u5931\u6027\u80fd\uff0c\u8fd8\u6709\u91cd\u7528\u8fde\u63a5\u7684\u4ee3\u4ef7\u592a\u9ad8\uff0c\u5219\u53ef\u4ee5\u4ec5\u4ec5\u901a\u8fc7\u8c03\u7528HttpUriRequest#abort()\u65b9\u6cd5\u6765\u4e2d\u6b62\u8bf7\u6c42\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpGet httpget = new HttpGet(\"http:\/\/localhost\/\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpResponse response = httpclient.execute(httpget);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpEntity entity = response.getEntity();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">if (entity != null) {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">InputStream instream = entity.getContent();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">int byteOne = instream.read();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">int byteTwo = instream.read();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\/\/ Do not need the rest<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">httpget.abort();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8fde\u63a5\u4e0d\u4f1a\u88ab\u91cd\u7528\uff0c\u4f46\u662f\u7531\u5b83\u6301\u6709\u7684\u6240\u6709\u7ea7\u522b\u7684\u8d44\u6e90\u5c06\u4f1a\u88ab\u6b63\u786e\u91ca\u653e\u3002<\/p>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.6 \u6d88\u8017\u5b9e\u4f53\u5185\u5bb9<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u63a8\u8350\u6d88\u8017\u5b9e\u4f53\u5185\u5bb9\u7684\u65b9\u5f0f\u662f\u4f7f\u7528\u5b83\u7684HttpEntity#getContent()\u6216HttpEntity#writeTo(OutputStream)\u65b9\u6cd5\u3002HttpClient\u4e5f\u81ea\u5e26EntityUtils\u7c7b\uff0c\u8fd9\u4f1a\u66b4\u9732\u51fa\u4e00\u4e9b\u9759\u6001\u65b9\u6cd5\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u66f4\u52a0\u5bb9\u6613\u5730\u4ece\u5b9e\u4f53\u4e2d\u8bfb\u53d6\u5185\u5bb9\u6216\u4fe1\u606f\u3002\u4ee3\u66ff\u76f4\u63a5\u8bfb\u53d6java.io.InputStream\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u7c7b\u4e2d\u7684\u65b9\u6cd5\u4ee5\u5b57\u7b26\u4e32\/\u5b57\u8282\u6570\u7ec4\u7684\u5f62\u5f0f\u83b7\u53d6\u6574\u4e2a\u5185\u5bb9\u4f53\u3002\u7136\u800c\uff0cEntityUtils\u7684\u4f7f\u7528\u662f\u5f3a\u70c8\u4e0d\u9f13\u52b1\u7684\uff0c\u9664\u975e\u54cd\u5e94\u5b9e\u4f53\u6e90\u81ea\u53ef\u9760\u7684HTTP\u670d\u52a1\u5668\u548c\u5df2\u77e5\u7684\u957f\u5ea6\u9650\u5236\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpGet httpget = new HttpGet(\"http:\/\/localhost\/\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpResponse response = httpclient.execute(httpget);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpEntity entity = response.getEntity();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">if (entity != null) {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">long len = entity.getContentLength();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">if (len != -1 &amp;&amp; len &lt; 2048) {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(EntityUtils.toString(entity));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">} else {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\/\/ Stream content out<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u4e0d\u6b62\u4e00\u6b21\u7684\u8bfb\u53d6\u5b9e\u4f53\u3002\u6b64\u65f6\u5b9e\u4f53\u5185\u5bb9\u5fc5\u987b\u4ee5\u67d0\u79cd\u65b9\u5f0f\u5728\u5185\u5b58\u6216\u78c1\u76d8\u4e0a\u88ab\u7f13\u51b2\u8d77\u6765\u3002\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u4f7f\u7528BufferedHttpEntity\u7c7b\u6765\u5305\u88c5\u6e90\u5b9e\u4f53\u5b8c\u6210\u3002\u8fd9\u4f1a\u5f15\u8d77\u6e90\u5b9e\u4f53\u5185\u5bb9\u88ab\u8bfb\u53d6\u5230\u5185\u5b58\u7684\u7f13\u51b2\u533a\u4e2d\u3002\u5728\u5176\u5b83\u6240\u6709\u65b9\u5f0f\u4e2d\uff0c\u5b9e\u4f53\u5305\u88c5\u5668\u5c06\u4f1a\u5f97\u5230\u6e90\u5b9e\u4f53\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpGet httpget = new HttpGet(\"http:\/\/localhost\/\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpResponse response = httpclient.execute(httpget);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpEntity entity = response.getEntity();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">if (entity != null) {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">entity = new BufferedHttpEntity(entity);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<\/blockquote>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.7 \u751f\u6210\u5b9e\u4f53\u5185\u5bb9<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient\u63d0\u4f9b\u4e00\u4e9b\u7c7b\uff0c\u5b83\u4eec\u53ef\u4ee5\u7528\u4e8e\u751f\u6210\u901a\u8fc7HTTP\u8fde\u63a5\u83b7\u5f97\u5185\u5bb9\u7684\u6709\u6548\u8f93\u51fa\u6d41\u3002\u4e3a\u4e86\u5c01\u95ed\u5b9e\u4f53\u4eceHTTP\u8bf7\u6c42\u4e2d\u83b7\u5f97\u7684\u8f93\u51fa\u5185\u5bb9\uff0c\u90a3\u4e9b\u7c7b\u7684\u5b9e\u4f8b\u53ef\u4ee5\u548c\u5c01\u95ed\u5982POST\u548cPUT\u8bf7\u6c42\u7684\u5b9e\u4f53\u76f8\u5173\u8054\u3002HttpClient\u4e3a\u5f88\u591a\u516c\u7528\u7684\u6570\u636e\u5bb9\u5668\uff0c\u6bd4\u5982\u5b57\u7b26\u4e32\uff0c\u5b57\u8282\u6570\u7ec4\uff0c\u8f93\u5165\u6d41\u548c\u6587\u4ef6\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7c7b\uff1aStringEntity\uff0cByteArrayEntity\uff0cInputStreamEntity\u548cFileEntity\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">File file = new File(\"somefile.txt\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">FileEntity entity = new FileEntity(file, \"text\/plain; charset=\\\"UTF-8\\\"\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpPost httppost = new HttpPost(\"http:\/\/localhost\/action.do\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">httppost.setEntity(entity);<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8bf7\u6ce8\u610fInputStreamEntity\u662f\u4e0d\u53ef\u91cd\u590d\u7684\uff0c\u56e0\u4e3a\u5b83\u4ec5\u4ec5\u80fd\u4ece\u4f4e\u5c42\u6570\u636e\u6d41\u4e2d\u8bfb\u53d6\u4e00\u6b21\u5185\u5bb9\u3002\u901a\u5e38\u6765\u8bf4\uff0c\u6211\u4eec\u63a8\u8350\u5b9e\u73b0\u4e00\u4e2a\u5b9a\u5236\u7684HttpEntity\u7c7b\uff0c\u8fd9\u662f\u81ea\u6211\u5305\u542b\u5f0f\u7684\uff0c\u7528\u6765\u4ee3\u66ff\u4f7f\u7528\u901a\u7528\u7684InputStreamEntity\u3002FileEntity\u4e5f\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u8d77\u70b9\u3002<\/p>\n<h5 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.7.1 \u52a8\u6001\u5185\u5bb9\u5b9e\u4f53<\/h5>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u901a\u5e38\u6765\u8bf4\uff0cHTTP\u5b9e\u4f53\u9700\u8981\u57fa\u4e8e\u7279\u5b9a\u7684\u6267\u884c\u4e0a\u4e0b\u6587\u6765\u52a8\u6001\u5730\u751f\u6210\u3002\u901a\u8fc7\u4f7f\u7528EntityTemplate\u5b9e\u4f53\u7c7b\u548cContentProducer\u63a5\u53e3\uff0cHttpClient\u63d0\u4f9b\u4e86\u52a8\u6001\u5b9e\u4f53\u7684\u652f\u6301\u3002\u5185\u5bb9\u751f\u6210\u5668\u662f\u6309\u7167\u9700\u6c42\u751f\u6210\u5b83\u4eec\u5185\u5bb9\u7684\u5bf9\u8c61\uff0c\u5c06\u5b83\u4eec\u5199\u5165\u5230\u4e00\u4e2a\u8f93\u51fa\u6d41\u4e2d\u3002\u5b83\u4eec\u662f\u6bcf\u6b21\u88ab\u8bf7\u6c42\u65f6\u6765\u751f\u6210\u5185\u5bb9\u3002\u6240\u4ee5\u7528EntityTemplate\u521b\u5efa\u7684\u5b9e\u4f53\u901a\u5e38\u662f\u81ea\u6211\u5305\u542b\u800c\u4e14\u53ef\u4ee5\u91cd\u590d\u7684\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">ContentProducer cp = new ContentProducer() {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">public void writeTo(OutputStream outstream) throws IOException {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Writer writer = new OutputStreamWriter(outstream, \"UTF-8\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">writer.write(\"&lt;response&gt;\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">writer.write(\" &lt;content&gt;\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">writer.write(\" important stuff\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">writer.write(\" &lt;\/content&gt;\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">writer.write(\"&lt;\/response&gt;\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">writer.flush();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">};<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpEntity entity = new EntityTemplate(cp);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpPost httppost = new HttpPost(\"http:\/\/localhost\/handler.do\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">httppost.setEntity(entity);<\/div>\n<\/blockquote>\n<h5 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.7.2 HTML\u8868\u5355<\/h5>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8bb8\u591a\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u9891\u7e41\u6a21\u62df\u63d0\u4ea4\u4e00\u4e2aHTML\u8868\u5355\u7684\u8fc7\u7a0b\uff0c\u6bd4\u5982\uff0c\u4e3a\u4e86\u6765\u8bb0\u5f55\u4e00\u4e2aWeb\u5e94\u7528\u7a0b\u5e8f\u6216\u63d0\u4ea4\u8f93\u51fa\u6570\u636e\u3002HttpClient\u63d0\u4f9b\u4e86\u7279\u6b8a\u7684\u5b9e\u4f53\u7c7bUrlEncodedFormEntity\u6765\u8fd9\u4e2a\u6ee1\u8db3\u8fc7\u7a0b\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">List&lt;NameValuePair&gt; formparams = new ArrayList&lt;NameValuePair&gt;();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">formparams.add(new BasicNameValuePair(\"param1\", \"value1\"));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">formparams.add(new BasicNameValuePair(\"param2\", \"value2\"));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, \"UTF-8\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpPost httppost = new HttpPost(\"http:\/\/localhost\/handler.do\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">httppost.setEntity(entity);<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">UrlEncodedFormEntity\u5b9e\u4f8b\u5c06\u4f1a\u4f7f\u7528URL\u7f16\u7801\u6765\u7f16\u7801\u53c2\u6570\uff0c\u751f\u6210\u5982\u4e0b\u7684\u5185\u5bb9\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">param1=value1&amp;param2=value2<\/p>\n<\/blockquote>\n<h5 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.7.3 \u5185\u5bb9\u5206\u5757<\/h5>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u901a\u5e38\uff0c\u6211\u4eec\u63a8\u8350\u8ba9HttpClient\u9009\u62e9\u57fa\u4e8e\u88ab\u4f20\u9012\u7684HTTP\u62a5\u6587\u5c5e\u6027\u7684\u6700\u9002\u5408\u7684\u7f16\u7801\u8f6c\u6362\u3002\u8fd9\u662f\u53ef\u80fd\u7684\uff0c\u4f46\u662f\uff0c\u8bbe\u7f6eHttpEntity#setChunked()\u65b9\u6cd5\u4e3atrue\u662f\u901a\u77e5HttpClient\u5206\u5757\u7f16\u7801\u7684\u9996\u9009\u3002\u8bf7\u6ce8\u610fHttpClient\u5c06\u4f1a\u4f7f\u7528\u6807\u8bc6\u4f5c\u4e3a\u63d0\u793a\u3002\u5f53\u4f7f\u7528\u7684HTTP\u534f\u8bae\u7248\u672c\uff0c\u5982HTTP\/1.0\u7248\u672c\uff0c\u4e0d\u652f\u6301\u5206\u5757\u7f16\u7801\u65f6\uff0c\u8fd9\u4e2a\u503c\u4f1a\u88ab\u5ffd\u7565\u3002<\/p>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">StringEntity entity = new StringEntity(\"important message\",<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\"text\/plain; charset=\\\"UTF-8\\\"\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">entity.setChunked(true);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpPost httppost = new HttpPost(\"http:\/\/localhost\/acrtion.do\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">httppost.setEntity(entity);<\/div>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.1.8 \u54cd\u5e94\u63a7\u5236\u5668<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u63a7\u5236\u54cd\u5e94\u7684\u6700\u7b80\u4fbf\u548c\u6700\u65b9\u4fbf\u7684\u65b9\u5f0f\u662f\u4f7f\u7528ResponseHandler\u63a5\u53e3\u3002\u8fd9\u4e2a\u653e\u5b8c\u5b8c\u5168\u51cf\u8f7b\u4e86\u7528\u6237\u5173\u4e8e\u8fde\u63a5\u7ba1\u7406\u7684\u62c5\u5fc3\u3002\u5f53\u4f7f\u7528ResponseHandler\u65f6\uff0cHttpClient\u5c06\u4f1a\u81ea\u52a8\u5173\u6ce8\u5e76\u4fdd\u8bc1\u91ca\u653e\u8fde\u63a5\u5230\u8fde\u63a5\u7ba1\u7406\u5668\u4e2d\u53bb\uff0c\u800c\u4e0d\u7ba1\u8bf7\u6c42\u6267\u884c\u662f\u5426\u6210\u529f\u6216\u5f15\u53d1\u4e86\u5f02\u5e38\u3002<\/p>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient httpclient = new DefaultHttpClient();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpGet httpget = new HttpGet(\"http:\/\/localhost\/\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">ResponseHandler&lt;byte[]&gt; handler = new ResponseHandler&lt;byte[]&gt;() {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">public byte[] handleResponse(<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpResponse response) throws ClientProtocolException, IOException {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpEntity entity = response.getEntity();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">if (entity != null) {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">return EntityUtils.toByteArray(entity);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">} else {<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">return null;<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">}<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">};<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">byte[] response = httpclient.execute(httpget, handler);<\/div>\n<\/blockquote>\n<h3 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.2 HTTP\u6267\u884c\u7684\u73af\u5883<\/h3>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u6700\u521d\uff0cHTTP\u662f\u88ab\u8bbe\u8ba1\u6210\u65e0\u72b6\u6001\u7684\uff0c\u9762\u5411\u8bf7\u6c42-\u54cd\u5e94\u7684\u534f\u8bae\u3002\u7136\u800c\uff0c\u771f\u5b9e\u7684\u5e94\u7528\u7a0b\u5e8f\u7ecf\u5e38\u9700\u8981\u901a\u8fc7\u4e00\u4e9b\u903b\u8f91\u76f8\u5173\u7684\u8bf7\u6c42-\u54cd\u5e94\u4ea4\u6362\u6765\u6301\u4e45\u72b6\u6001\u4fe1\u606f\u3002\u4e3a\u4e86\u5f00\u542f\u5e94\u7528\u7a0b\u5e8f\u6765\u7ef4\u6301\u4e00\u4e2a\u8fc7\u7a0b\u72b6\u6001\uff0cHttpClient\u5141\u8bb8HTTP\u8bf7\u6c42\u5728\u4e00\u4e2a\u7279\u5b9a\u7684\u6267\u884c\u73af\u5883\u4e2d\u6765\u6267\u884c\uff0c\u7b80\u79f0\u4e3aHTTP\u4e0a\u4e0b\u6587\u3002\u5982\u679c\u76f8\u540c\u7684\u73af\u5883\u5728\u8fde\u7eed\u8bf7\u6c42\u4e4b\u95f4\u91cd\u7528\uff0c\u90a3\u4e48\u591a\u79cd\u903b\u8f91\u76f8\u5173\u7684\u8bf7\u6c42\u53ef\u4ee5\u53c2\u4e0e\u5230\u4e00\u4e2a\u903b\u8f91\u4f1a\u8bdd\u4e2d\u3002HTTP\u4e0a\u4e0b\u6587\u529f\u80fd\u548cjava.util.Map&lt;String,Object&gt;\u5f88\u76f8\u4f3c\u3002\u5b83\u4ec5\u4ec5\u662f\u4efb\u610f\u547d\u540d\u53c2\u6570\u503c\u7684\u96c6\u5408\u3002\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5728\u8bf7\u6c42\u4e4b\u524d\u6216\u5728\u68c0\u67e5\u4e0a\u4e0b\u6587\u6267\u884c\u5b8c\u6210\u4e4b\u540e\u6765\u586b\u5145\u4e0a\u4e0b\u6587\u5c5e\u6027\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5728HTTP\u8bf7\u6c42\u6267\u884c\u7684\u8fd9\u4e00\u8fc7\u7a0b\u4e2d\uff0cHttpClient\u6dfb\u52a0\u4e86\u4e0b\u5217\u5c5e\u6027\u5230\u6267\u884c\u4e0a\u4e0b\u6587\u4e2d\uff1a<\/p>\n<ul style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.connection'\uff1aHttpConnection\u5b9e\u4f8b\u4ee3\u8868\u4e86\u8fde\u63a5\u5230\u76ee\u6807\u670d\u52a1\u5668\u7684\u771f\u5b9e\u8fde\u63a5\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.target_host'\uff1aHttpHost\u5b9e\u4f8b\u4ee3\u8868\u4e86\u8fde\u63a5\u76ee\u6807\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.proxy_host'\uff1a\u5982\u679c\u4f7f\u7528\u4e86\uff0cHttpHost\u5b9e\u4f8b\u4ee3\u8868\u4e86\u4ee3\u7406\u8fde\u63a5\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.request'\uff1aHttpRequest\u5b9e\u4f8b\u4ee3\u8868\u4e86\u771f\u5b9e\u7684HTTP\u8bf7\u6c42\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.response'\uff1aHttpResponse\u5b9e\u4f8b\u4ee3\u8868\u4e86\u771f\u5b9e\u7684HTTP\u54cd\u5e94\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.request_sent'\uff1ajava.lang.Boolean\u5bf9\u8c61\u4ee3\u8868\u4e86\u6697\u793a\u771f\u5b9e\u8bf7\u6c42\u662f\u5426\u88ab\u5b8c\u5168\u4f20\u9001\u5230\u76ee\u6807\u8fde\u63a5\u7684\u6807\u8bc6\u3002<\/li>\n<\/ul>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u6bd4\u5982\uff0c\u4e3a\u4e86\u51b3\u5b9a\u6700\u7ec8\u7684\u91cd\u5b9a\u5411\u76ee\u6807\uff0c\u5728\u8bf7\u6c42\u6267\u884c\u4e4b\u540e\uff0c\u53ef\u4ee5\u68c0\u67e5http.target_host\u5c5e\u6027\u7684\u503c\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">DefaultHttpClient httpclient = new DefaultHttpClient();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpContext localContext = new BasicHttpContext();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpGet httpget = new HttpGet(\"http:\/\/www.google.com\/\");<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpResponse response = httpclient.execute(httpget, localContext);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpHost target = (HttpHost) localContext.getAttribute(<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>ExecutionContext.HTTP_TARGET_HOST);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>System.out.println(\"Final target: \" + target);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpEntity entity = response.getEntity();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>if (entity != null) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>entity.consumeContent();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<\/div>\n<\/blockquote>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">Final target: http:\/\/www.google.ch<\/p>\n<\/blockquote>\n<h3 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.3 \u5f02\u5e38\u5904\u7406<\/h3>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient\u80fd\u591f\u629b\u51fa\u4e24\u79cd\u7c7b\u578b\u7684\u5f02\u5e38\uff1a\u5728I\/O\u5931\u8d25\u65f6\uff0c\u5982\u5957\u63a5\u5b57\u8fde\u63a5\u8d85\u65f6\u6216\u88ab\u91cd\u7f6e\u7684java.io.IOException\u5f02\u5e38\uff0c\u8fd8\u6709\u6807\u5fd7HTTP\u8bf7\u6c42\u5931\u8d25\u7684\u4fe1\u53f7\uff0c\u5982\u8fdd\u53cdHTTP\u534f\u8bae\u7684HttpException\u5f02\u5e38\u3002\u901a\u5e38I\/O\u9519\u8bef\u88ab\u8ba4\u4e3a\u662f\u975e\u81f4\u547d\u7684\u548c\u53ef\u4ee5\u6062\u590d\u7684\uff0c\u800cHTTP\u534f\u8bae\u9519\u8bef\u5219\u88ab\u8ba4\u4e3a\u662f\u81f4\u547d\u7684\u800c\u4e14\u662f\u4e0d\u80fd\u81ea\u52a8\u6062\u590d\u7684\u3002<\/p>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.3.1 HTTP\u8fd0\u8f93\u5b89\u5168<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8981\u7406\u89e3HTTP\u534f\u8bae\u5e76\u4e0d\u662f\u5bf9\u6240\u6709\u7c7b\u578b\u7684\u5e94\u7528\u7a0b\u5e8f\u90fd\u9002\u5408\u7684\uff0c\u8fd9\u4e00\u70b9\u5f88\u91cd\u8981\u3002HTTP\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u9762\u5411\u8bf7\u6c42\/\u54cd\u5e94\u7684\u534f\u8bae\uff0c\u6700\u521d\u88ab\u8bbe\u8ba1\u7528\u6765\u652f\u6301\u53d6\u56de\u9759\u6001\u6216\u52a8\u6001\u751f\u6210\u7684\u5185\u5bb9\u3002\u5b83\u4ece\u672a\u5411\u652f\u6301\u4e8b\u52a1\u6027\u64cd\u4f5c\u65b9\u5411\u53d1\u5c55\u3002\u6bd4\u5982\uff0c\u5982\u679c\u6210\u529f\u6536\u5230\u548c\u5904\u7406\u8bf7\u6c42\uff0cHTTP\u670d\u52a1\u5668\u5c06\u4f1a\u8003\u8651\u5b83\u7684\u5176\u4e2d\u4e00\u90e8\u5206\u662f\u5426\u5b8c\u6210\uff0c\u751f\u6210\u4e00\u4e2a\u54cd\u5e94\u5e76\u53d1\u9001\u4e00\u4e2a\u72b6\u6001\u7801\u5230\u5ba2\u6237\u7aef\u3002\u5982\u679c\u5ba2\u6237\u7aef\u56e0\u4e3a\u8bfb\u53d6\u8d85\u65f6\uff0c\u8bf7\u6c42\u53d6\u6d88\u6216\u7cfb\u7edf\u5d29\u6e83\u5bfc\u81f4\u63a5\u6536\u54cd\u5e94\u5b9e\u4f53\u5931\u8d25\u65f6\uff0c\u670d\u52a1\u5668\u4e0d\u4f1a\u8bd5\u56fe\u56de\u6eda\u4e8b\u52a1\u3002\u5982\u679c\u5ba2\u6237\u7aef\u51b3\u5b9a\u91cd\u65b0\u8fd9\u4e2a\u8bf7\u6c42\uff0c\u90a3\u4e48\u670d\u52a1\u5668\u5c06\u4e0d\u53ef\u907f\u514d\u5730\u4e0d\u6b62\u4e00\u6b21\u6267\u884c\u8fd9\u4e2a\u76f8\u540c\u7684\u4e8b\u52a1\u3002\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u5e94\u7528\u6570\u636e\u635f\u574f\u6216\u8005\u4e0d\u4e00\u81f4\u7684\u5e94\u7528\u7a0b\u5e8f\u72b6\u6001\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5c3d\u7ba1HTTP\u4ece\u6765\u90fd\u6ca1\u6709\u88ab\u8bbe\u8ba1\u6765\u652f\u6301\u4e8b\u52a1\u6027\u5904\u7406\uff0c\u4f46\u5b83\u4e5f\u80fd\u88ab\u7528\u4f5c\u4e8e\u4e00\u4e2a\u4f20\u8f93\u534f\u8bae\u5bf9\u5173\u952e\u7684\u4efb\u52a1\u5e94\u7528\u63d0\u4f9b\u88ab\u6ee1\u8db3\u7684\u786e\u5b9a\u72b6\u6001\u3002\u8981\u4fdd\u8bc1HTTP\u4f20\u8f93\u5c42\u7684\u5b89\u5168\uff0c\u7cfb\u7edf\u5fc5\u987b\u4fdd\u8bc1HTTP\u65b9\u6cd5\u5728\u5e94\u7528\u5c42\u7684\u5e42\u7b49\u6027\u3002<\/p>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.3.2 \u5e42\u7b49\u7684\u65b9\u6cd5<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HTTP\/1.1 \u660e\u786e\u5730\u5b9a\u4e49\u4e86\u5e42\u7b49\u7684\u65b9\u6cd5\uff0c\u63cf\u8ff0\u5982\u4e0b<\/p>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">[\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u6709\u201c\u5e42\u7b49\u201d\u5c5e\u6027\u5728\u90a3\u4e9b\uff08\u9664\u4e86\u9519\u8bef\u6216\u8fc7\u671f\u95ee\u9898\uff09N\u7684\u526f\u4f5c\u7528&gt;0\u7684\u76f8\u540c\u8bf7\u6c42\u548c\u72ec\u7acb\u7684\u8bf7\u6c42\u662f\u76f8\u540c\u7684]<\/div>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u6362\u53e5\u8bdd\u8bf4\uff0c\u5e94\u7528\u7a0b\u5e8f\u5e94\u8be5\u4fdd\u8bc1\u51c6\u5907\u7740\u6765\u5904\u7406\u591a\u4e2a\u76f8\u540c\u65b9\u6cd5\u6267\u884c\u7684\u5b9e\u73b0\u3002\u8fd9\u662f\u53ef\u4ee5\u8fbe\u5230\u7684\uff0c\u6bd4\u5982\uff0c\u901a\u8fc7\u63d0\u4f9b\u4e00\u4e2a\u72ec\u7acb\u7684\u4e8b\u52a1ID\u548c\u5176\u5b83\u907f\u514d\u6267\u884c\u76f8\u540c\u903b\u8f91\u64cd\u4f5c\u7684\u65b9\u6cd5\u3002<\/p>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8bf7\u6ce8\u610f\u8fd9\u4e2a\u95ee\u9898\u5bf9\u4e8eHttpClient\u662f\u4e0d\u5177\u4f53\u7684\u3002\u57fa\u4e8e\u5e94\u7528\u7684\u6d4f\u89c8\u5668\u7279\u522b\u53d7\u548c\u975e\u5e42\u7b49\u7684HTTP\u65b9\u6cd5\u76f8\u5173\u7684\u76f8\u540c\u95ee\u9898\u7684\u9650\u5236\u3002<\/div>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpClient\u5047\u8bbe\u6ca1\u6709\u5b9e\u4f53\u5305\u542b\u65b9\u6cd5\uff0c\u6bd4\u5982GET\u548cHEAD\u662f\u5e42\u7b49\u7684\uff0c\u800c\u5b9e\u4f53\u5305\u542b\u65b9\u6cd5\uff0c\u6bd4\u5982POST\u548cPUT\u5219\u4e0d\u662f\u3002<\/p>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.3.3 \u5f02\u5e38\u81ea\u52a8\u6062\u590d<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cHttpClient\u4f1a\u8bd5\u56fe\u81ea\u52a8\u4eceI\/O\u5f02\u5e38\u4e2d\u6062\u590d\u3002\u9ed8\u8ba4\u7684\u81ea\u52a8\u6062\u590d\u673a\u5236\u662f\u53d7\u5f88\u5c11\u4e00\u90e8\u5206\u5df2\u77e5\u7684\u5f02\u5e38\u662f\u5b89\u5168\u7684\u8fd9\u4e2a\u9650\u5236\u3002<\/p>\n<ul style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">HttpClient\u4e0d\u4f1a\u4ece\u4efb\u610f\u903b\u8f91\u6216HTTP\u534f\u8bae\u9519\u8bef\uff08\u90a3\u4e9b\u662f\u4eceHttpException\u7c7b\u4e2d\u6d3e\u751f\u51fa\u7684\uff09\u4e2d\u6062\u590d\u7684\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">HttpClient\u5c06\u4f1a\u81ea\u52a8\u91cd\u65b0\u6267\u884c\u90a3\u4e48\u5047\u8bbe\u662f\u5e42\u7b49\u7684\u65b9\u6cd5\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">HttpClient\u5c06\u4f1a\u81ea\u52a8\u91cd\u65b0\u6267\u884c\u90a3\u4e9b\u7531\u4e8e\u8fd0\u8f93\u5f02\u5e38\u5931\u8d25\uff0c\u800cHTTP\u8bf7\u6c42\u4ecd\u7136\u88ab\u4f20\u9001\u5230\u76ee\u6807\u670d\u52a1\u5668\uff08\u4e5f\u5c31\u662f\u8bf7\u6c42\u6ca1\u6709\u5b8c\u5168\u88ab\u9001\u5230\u670d\u52a1\u5668\uff09\u5931\u8d25\u7684\u65b9\u6cd5\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">HttpClient\u5c06\u4f1a\u81ea\u52a8\u91cd\u65b0\u6267\u884c\u90a3\u4e9b\u5df2\u7ecf\u5b8c\u5168\u88ab\u9001\u5230\u670d\u52a1\u5668\uff0c\u4f46\u662f\u670d\u52a1\u5668\u4f7f\u7528HTTP\u72b6\u6001\u7801\uff08\u670d\u52a1\u5668\u4ec5\u4ec5\u4e22\u6389\u8fde\u63a5\u800c\u4e0d\u4f1a\u53d1\u56de\u4efb\u4f55\u4e1c\u897f\uff09\u54cd\u5e94\u65f6\u5931\u8d25\u7684\u65b9\u6cd5\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5047\u8bbe\u8bf7\u6c42\u6ca1\u6709\u88ab\u670d\u52a1\u5668\u5904\u7406\uff0c\u800c\u5e94\u7528\u7a0b\u5e8f\u7684\u72b6\u6001\u4e5f\u6ca1\u6709\u6539\u53d8\u3002\u5982\u679c\u8fd9\u4e2a\u5047\u8bbe\u53ef\u80fd\u5bf9\u4e8e\u4f60\u5e94\u7528\u7a0b\u5e8f\u7684\u76ee\u6807Web\u670d\u52a1\u5668\u6765\u8bf4\u4e0d\u6b63\u786e\uff0c\u90a3\u4e48\u5c31\u5f3a\u70c8\u5efa\u8bae\u63d0\u4f9b\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u5f02\u5e38\u5904\u7406\u5668\u3002<\/li>\n<\/ul>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.3.4 \u8bf7\u6c42\u91cd\u8bd5\u5904\u7406<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u4e3a\u4e86\u5f00\u542f\u81ea\u5b9a\u4e49\u5f02\u5e38\u6062\u590d\u673a\u5236\uff0c\u5e94\u8be5\u63d0\u4f9b\u4e00\u4e2aHttpRequestRetryHandler\u63a5\u53e3\u7684\u5b9e\u73b0\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">DefaultHttpClient httpclient = new DefaultHttpClient();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>public boolean retryRequest(IOException exception,<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>int executionCount,HttpContext context) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>if (executionCount &gt;= 5) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>\/\/ \u5982\u679c\u8d85\u8fc7\u6700\u5927\u91cd\u8bd5\u6b21\u6570\uff0c\u90a3\u4e48\u5c31\u4e0d\u8981\u7ee7\u7eed\u4e86<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>return false;<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>if (exception instanceof NoHttpResponseException) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>\/\/ \u5982\u679c\u670d\u52a1\u5668\u4e22\u6389\u4e86\u8fde\u63a5\uff0c\u90a3\u4e48\u5c31\u91cd\u8bd5<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>return true;<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>if (exception instanceof SSLHandshakeException) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>\/\/ \u4e0d\u8981\u91cd\u8bd5SSL\u63e1\u624b\u5f02\u5e38<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>return false;<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpRequest request = (HttpRequest) context.getAttribute(<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>ExecutionContext.HTTP_REQUEST);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>if (idempotent) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>\/\/ \u5982\u679c\u8bf7\u6c42\u88ab\u8ba4\u4e3a\u662f\u5e42\u7b49\u7684\uff0c\u90a3\u4e48\u5c31\u91cd\u8bd5<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>return true;<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>return false;<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>};<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>httpclient.setHttpRequestRetryHandler(myRetryHandler);<\/div>\n<\/blockquote>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\n<h3 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.4 \u4e2d\u6b62\u8bf7\u6c42<\/h3>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u7531\u4e8e\u76ee\u6807\u670d\u52a1\u5668\u7684\u9ad8\u8d1f\u8f7d\u6216\u5ba2\u6237\u7aef\u6709\u5f88\u591a\u6d3b\u52a8\u7684\u8bf7\u6c42\uff0c\u90a3\u4e48HTTP\u8bf7\u6c42\u6267\u884c\u4f1a\u5728\u9884\u671f\u7684\u65f6\u95f4\u6846\u5185\u800c\u5931\u8d25\u3002\u8fd9\u65f6\uff0c\u5c31\u53ef\u80fd\u4e0d\u5f97\u4e0d\u8fc7\u65e9\u5730\u4e2d\u6b62\u8bf7\u6c42\uff0c\u89e3\u9664\u5c01\u9501\u5728I\/O\u6267\u884c\u4e2d\u7684\u7ebf\u7a0b\u5c01\u9501\u3002\u88abHttpClient\u6267\u884c\u7684HTTP\u8bf7\u6c42\u53ef\u4ee5\u5728\u6267\u884c\u7684\u4efb\u610f\u9636\u6bb5\u901a\u8fc7\u8c03\u7528HttpUriRequest#abort()\u65b9\u6cd5\u800c\u4e2d\u6b62\u3002\u8fd9\u4e2a\u65b9\u6cd5\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u800c\u4e14\u53ef\u4ee5\u4ece\u4efb\u610f\u7ebf\u7a0b\u4e2d\u8c03\u7528\u3002\u5f53\u4e00\u4e2aHTTP\u8bf7\u6c42\u88ab\u4e2d\u6b62\u65f6\uff0c\u5b83\u7684\u6267\u884c\u7ebf\u7a0b\u5c31\u5c01\u9501\u5728I\/O\u64cd\u4f5c\u4e2d\u4e86\uff0c\u800c\u4e14\u4fdd\u8bc1\u901a\u8fc7\u629b\u51faInterruptedIOException\u5f02\u5e38\u6765\u89e3\u9501\u3002<\/p>\n<h3 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.5 HTTP\u534f\u8bae\u62e6\u622a\u5668<\/h3>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HTTP\u534f\u8bae\u62e6\u622a\u5668\u662f\u4e00\u4e2a\u5b9e\u73b0\u4e86\u7279\u5b9aHTPP\u534f\u8bae\u65b9\u9762\u7684\u60ef\u4f8b\u3002\u901a\u5e38\u534f\u8bae\u62e6\u622a\u5668\u5e0c\u671b\u4f5c\u7528\u4e8e\u4e00\u4e2a\u7279\u5b9a\u5934\u90e8\u4fe1\u606f\u4e0a\uff0c\u6216\u8005\u4e00\u65cf\u6536\u5230\u62a5\u6587\u7684\u76f8\u5173\u5934\u90e8\u4fe1\u606f\uff0c\u6216\u4f7f\u7528\u4e00\u4e2a\u7279\u5b9a\u7684\u5934\u90e8\u6216\u4e00\u65cf\u76f8\u5173\u7684\u5934\u90e8\u4fe1\u606f\u586b\u5145\u53d1\u51fa\u7684\u62a5\u6587\u3002\u534f\u8bae\u62e6\u622a\u5668\u4e5f\u53ef\u4ee5\u64cd\u7eb5\u5305\u542b\u5728\u62a5\u6587\u4e2d\u7684\u5185\u5bb9\u5b9e\u4f53\uff0c\u900f\u660e\u7684\u5185\u5bb9\u538b\u7f29\/\u89e3\u538b\u5c31\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u793a\u4f8b\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\u8fd9\u662f\u7531\u5305\u88c5\u5668\u5b9e\u4f53\u7c7b\u4f7f\u7528\u4e86\u201c\u88c5\u9970\u8005\u201d\u6a21\u5f0f\u6765\u88c5\u9970\u539f\u59cb\u7684\u5b9e\u4f53\u5b8c\u6210\u7684\u3002\u4e00\u4e9b\u534f\u8bae\u62e6\u622a\u5668\u53ef\u4ee5\u4ece\u4e00\u4e2a\u903b\u8f91\u5355\u5143\u4e2d\u6765\u7ed3\u5408\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u534f\u8bae\u62e6\u622a\u5668\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5171\u4eab\u4fe1\u606f\u6765\u5171\u540c\u5408\u4f5c-\u6bd4\u5982\u5904\u7406\u72b6\u6001-\u901a\u8fc7HTTP\u6267\u884c\u4e0a\u4e0b\u6587\u3002\u534f\u8bae\u62e6\u622a\u5668\u53ef\u4ee5\u4f7f\u7528HTTP\u5185\u5bb9\u6765\u4e3a\u4e00\u4e2a\u6216\u591a\u4e2a\u8fde\u7eed\u7684\u8bf7\u6c42\u5b58\u50a8\u4e00\u4e2a\u5904\u7406\u72b6\u6001\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u901a\u5e38\u62e6\u622a\u5668\u6267\u884c\u7684\u987a\u5e8f\u4e0d\u5e94\u8be5\u548c\u5b83\u4eec\u57fa\u4e8e\u7684\u7279\u5b9a\u6267\u884c\u4e0a\u4e0b\u6587\u72b6\u6001\u6709\u5173\u3002\u5982\u679c\u534f\u8bae\u62e6\u622a\u5668\u6709\u76f8\u4e92\u4f9d\u5b58\u5173\u7cfb\uff0c\u90a3\u4e48\u5b83\u4eec\u5fc5\u987b\u6309\u7279\u5b9a\u987a\u5e8f\u6765\u6267\u884c\uff0c\u6b63\u5982\u5b83\u4eec\u5e0c\u671b\u6267\u884c\u7684\u987a\u5e8f\u4e00\u6837\uff0c\u5b83\u4eec\u5e94\u8be5\u5728\u76f8\u540c\u7684\u5e8f\u5217\u4e2d\u88ab\u52a0\u5230\u534f\u8bae\u5904\u7406\u5668\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u534f\u8bae\u62e6\u622a\u5668\u5fc5\u987b\u5b9e\u73b0\u4e3a\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\u548cServlet\u76f8\u4f3c\uff0c\u534f\u8bae\u62e6\u622a\u5668\u4e0d\u5e94\u8be5\u4f7f\u7528\u5b9e\u4f8b\u53d8\u91cf\uff0c\u9664\u975e\u8bbf\u95ee\u7684\u90a3\u4e9b\u53d8\u91cf\u662f\u540c\u6b65\u7684\u3002<\/p>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8fd9\u4e2a\u793a\u4f8b\u7ed9\u51fa\u4e86\u672c\u5730\u5185\u5bb9\u5728\u8fde\u7eed\u7684\u8bf7\u6c42\u4e2d\u600e\u4e48\u88ab\u7528\u4e8e\u6301\u4e45\u4e00\u4e2a\u5904\u7406\u72b6\u6001\u7684\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">DefaultHttpClient httpclient = new DefaultHttpClient();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpContext localContext = new BasicHttpContext();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>AtomicInteger count = new AtomicInteger(1);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>localContext.setAttribute(\"count\", count);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>httpclient.addRequestInterceptor(new HttpRequestInterceptor() {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>public void process(final HttpRequest request,<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>final HttpContext context) throws HttpException, IOException {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>AtomicInteger count = (AtomicInteger) context.getAttribute(\"count\");<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>request.addHeader(\"Count\", Integer.toString(count.getAndIncrement()));<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>});<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpGet httpget = new HttpGet(\"http:\/\/localhost\/\");<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>for (int i = 0; i &lt; 10; i++) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpResponse response = httpclient.execute(httpget, localContext);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpEntity entity = response.getEntity();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>if (entity != null) {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>entity.consumeContent();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<\/div>\n<\/blockquote>\n<h3 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.6 HTTP\u53c2\u6570<\/h3>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpParams\u63a5\u53e3\u4ee3\u8868\u4e86\u5b9a\u4e49\u7ec4\u4ef6\u8fd0\u884c\u65f6\u884c\u4e3a\u7684\u4e00\u4e2a\u4e0d\u53d8\u7684\u503c\u7684\u96c6\u5408\u3002\u5f88\u591a\u60c5\u51b5\u4e0b\uff0cHttpParams\u548cHttpContext\u76f8\u4f3c\u3002\u4e8c\u8005\u4e4b\u95f4\u7684\u4e3b\u8981\u533a\u522b\u662f\u5b83\u4eec\u5728\u8fd0\u884c\u65f6\u4f7f\u7528\u7684\u4e0d\u540c\u3002\u8fd9\u4e24\u4e2a\u63a5\u53e3\u8868\u793a\u4e86\u5bf9\u8c61\u7684\u96c6\u5408\uff0c\u5b83\u4eec\u88ab\u89c6\u4f5c\u4e3a\u8bbf\u95ee\u5bf9\u8c61\u503c\u7684\u952e\u7684Map\uff0c\u4f46\u662f\u670d\u52a1\u4e8e\u4e0d\u540c\u7684\u76ee\u7684\uff1a<\/p>\n<ul style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">HttpParams\u65e8\u5728\u5305\u542b\u7b80\u5355\u5bf9\u8c61\uff1a\u6574\u578b\uff0c\u6d6e\u70b9\u578b\uff0c\u5b57\u7b26\u4e32\uff0c\u96c6\u5408\uff0c\u8fd8\u6709\u8fd0\u884c\u65f6\u4e0d\u53d8\u7684\u5bf9\u8c61\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">HttpParams\u5e0c\u671b\u88ab\u7528\u5728\u201c\u4e00\u6b21\u5199\u5165-\u591a\u5904\u51c6\u5907\u201d\u6a21\u5f0f\u4e0b\u3002HttpContext\u65e8\u5728\u5305\u542b\u5f88\u53ef\u80fd\u5728HTTP\u62a5\u6587\u5904\u7406\u8fd9\u4e00\u8fc7\u7a0b\u4e2d\u53d1\u751f\u6539\u53d8\u7684\u590d\u6742\u5bf9\u8c61<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">HttpParams\u7684\u76ee\u6807\u662f\u5b9a\u4e49\u5176\u5b83\u7ec4\u4ef6\u7684\u884c\u4e3a\u3002\u901a\u5e38\u6bcf\u4e00\u4e2a\u590d\u6742\u7684\u7ec4\u4ef6\u90fd\u6709\u5b83\u81ea\u5df1\u7684HttpParams\u5bf9\u8c61\u3002HttpContext\u7684\u76ee\u6807\u662f\u6765\u8868\u793a\u4e00\u4e2aHTTP\u5904\u7406\u7684\u6267\u884c\u72b6\u6001\u3002\u901a\u5e38\u76f8\u540c\u7684\u6267\u884c\u4e0a\u4e0b\u6587\u5728\u5f88\u591a\u5408\u4f5c\u7684\u5bf9\u8c61\u4e2d\u5171\u4eab\u3002<\/li>\n<\/ul>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.6.1 \u53c2\u6570\u5c42\u6b21<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u5728HTTP\u8bf7\u6c42\u6267\u884c\u8fc7\u7a0b\u4e2d\uff0cHttpRequest\u5bf9\u8c61\u7684HttpParams\u662f\u548c\u7528\u4e8e\u6267\u884c\u8bf7\u6c42\u7684HttpClient\u5b9e\u4f8b\u7684HttpParams\u8054\u7cfb\u5728\u4e00\u8d77\u7684\u3002\u8fd9\u4f7f\u5f97\u8bbe\u7f6e\u5728HTTP\u8bf7\u6c42\u7ea7\u522b\u7684\u53c2\u6570\u4f18\u5148\u4e8e\u8bbe\u7f6e\u5728HTTP\u5ba2\u6237\u7aef\u7ea7\u522b\u7684HttpParams\u3002\u63a8\u8350\u7684\u505a\u6cd5\u662f\u8bbe\u7f6e\u666e\u901a\u53c2\u6570\u5bf9\u6240\u6709\u7684\u5728HTTP\u5ba2\u6237\u7aef\u7ea7\u522b\u7684HTTP\u8bf7\u6c42\u5171\u4eab\uff0c\u800c\u4e14\u53ef\u4ee5\u9009\u62e9\u6027\u91cd\u5199\u5177\u4f53\u5728HTTP\u8bf7\u6c42\u7ea7\u522b\u7684\u53c2\u6570\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">DefaultHttpClient httpclient = new DefaultHttpClient();<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_0);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>httpclient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,\"UTF-8\");<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>HttpGet httpget = new HttpGet(\"http:\/\/www.google.com\/\");<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>httpget.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>httpget.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,Boolean.FALSE);<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>httpclient.addRequestInterceptor(new HttpRequestInterceptor() {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>public void process(final HttpRequest request,<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>final HttpContext context) throws HttpException, IOException {<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>System.out.println(request.getParams().getParameter(<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>CoreProtocolPNames.PROTOCOL_VERSION));<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>System.out.println(request.getParams().getParameter(<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>CoreProtocolPNames.HTTP_CONTENT_CHARSET));<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>System.out.println(request.getParams().getParameter(<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>CoreProtocolPNames.USE_EXPECT_CONTINUE));<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>System.out.println(request.getParams().getParameter(<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>CoreProtocolPNames.STRICT_TRANSFER_ENCODING));<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>}<br style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\" \/>});<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HTTP\/1.1<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">UTF-8<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">false<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">null<\/div>\n<\/blockquote>\n<h4 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.6.2 HTTP\u53c2\u6570bean<\/h4>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpParams\u63a5\u53e3\u5141\u8bb8\u5728\u5904\u7406\u7ec4\u4ef6\u7684\u914d\u7f6e\u4e0a\u5f88\u5927\u7684\u7075\u6d3b\u6027\u3002\u5f88\u91cd\u8981\u7684\u662f\uff0c\u65b0\u7684\u53c2\u6570\u53ef\u4ee5\u88ab\u5f15\u5165\u800c\u4e0d\u4f1a\u5f71\u54cd\u8001\u7248\u672c\u7684\u4e8c\u8fdb\u5236\u517c\u5bb9\u6027\u3002\u7136\u800c\uff0c\u548c\u5e38\u89c4\u7684Java bean\u76f8\u6bd4\uff0cHttpParams\u4e5f\u6709\u4e00\u4e2a\u7f3a\u70b9\uff1aHttpParams\u4e0d\u80fd\u4f7f\u7528DI\u6846\u67b6\u6765\u7ec4\u5408\u3002\u4e3a\u4e86\u7f13\u89e3\u8fd9\u4e2a\u9650\u5236\uff0cHttpClient\u5305\u542b\u4e86\u4e00\u4e9bbean\u7c7b\uff0c\u5b83\u4eec\u53ef\u4ee5\u7528\u6765\u6309\u987a\u5e8f\u4f7f\u7528\u6807\u51c6\u7684Java eban\u60ef\u4f8b\u521d\u59cb\u5316HttpParams\u5bf9\u8c61\u3002<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpParams params = new BasicHttpParams();<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HttpProtocolParamBean paramsBean = new HttpProtocolParamBean(params);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">paramsBean.setVersion(HttpVersion.HTTP_1_1);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">paramsBean.setContentCharset(\"UTF-8\");<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">paramsBean.setUseExpectContinue(true);<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(params.getParameter(<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">CoreProtocolPNames.PROTOCOL_VERSION));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(params.getParameter(<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">CoreProtocolPNames.HTTP_CONTENT_CHARSET));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(params.getParameter(<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">CoreProtocolPNames.USE_EXPECT_CONTINUE));<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">System.out.println(params.getParameter(<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">CoreProtocolPNames.USER_AGENT));<\/div>\n<\/blockquote>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8f93\u51fa\u5185\u5bb9\u4e3a\uff1a<\/p>\n<blockquote style=\"font-family: Verdana, Arial, Tahoma, sans-serif; background-image: url('http:\/\/simpleframework.net\/$resource\/default\/css\/blue\/images\/quote.png'); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9ff; margin-top: 4px !important; margin-right: 2px !important; margin-bottom: 4px !important; margin-left: 2px !important; padding-top: 8px !important; padding-right: 6px !important; padding-bottom: 8px !important; padding-left: 40px !important; border-top-left-radius: 6px 6px; border-top-right-radius: 6px 6px; border-bottom-right-radius: 6px 6px; border-bottom-left-radius: 6px 6px; background-position: 4px 0px; background-repeat: no-repeat no-repeat; border-width: 2px; border-color: #dddddd; border-style: dashed;\">\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">HTTP\/1.1<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">UTF-8<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">false<\/div>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">null<\/div>\n<\/blockquote>\n<div style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\n<h3 style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">1.7 HTTP\u8bf7\u6c42\u6267\u884c\u53c2\u6570<\/h3>\n<p style=\"font-family: inherit; font-style: inherit; font-size: inherit; color: inherit;\">\u8fd9\u4e9b\u53c2\u6570\u4f1a\u5f71\u54cd\u5230\u8bf7\u6c42\u6267\u884c\u7684\u8fc7\u7a0b\uff1a<\/p>\n<ul style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.protocol.version'\uff1a\u5982\u679c\u6ca1\u6709\u5728\u8bf7\u6c42\u5bf9\u8c61\u4e2d\u8bbe\u7f6e\u660e\u786e\u7684\u7248\u672c\u4fe1\u606f\uff0c\u5b83\u5c31\u5b9a\u4e49\u4e86\u4f7f\u7528\u7684HTTP\u534f\u8bae\u7248\u672c\u3002\u8fd9\u4e2a\u53c2\u6570\u671f\u671b\u5f97\u5230\u4e00\u4e2aProtocolVersion\u7c7b\u578b\u7684\u503c\u3002\u5982\u679c\u8fd9\u4e2a\u53c2\u6570\u6ca1\u6709\u88ab\u8bbe\u7f6e\uff0c\u90a3\u4e48\u5c31\u4f7f\u7528HTTP\/1.1\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.protocol.element-charset'\uff1a\u5b9a\u4e49\u4e86\u7f16\u7801HTTP\u534f\u8bae\u5143\u7d20\u7684\u5b57\u7b26\u96c6\u3002\u8fd9\u4e2a\u53c2\u6570\u671f\u671b\u5f97\u5230\u4e00\u4e2ajava.lang.String\u7c7b\u578b\u7684\u503c\u3002\u5982\u679c\u8fd9\u4e2a\u53c2\u6570\u6ca1\u6709\u88ab\u8bbe\u7f6e\uff0c\u90a3\u4e48\u5c31\u4f7f\u7528US-ASCII\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.protocol.eontent-charset'\uff1a\u5b9a\u4e49\u4e86\u4e3a\u6bcf\u4e2a\u5185\u5bb9\u4e3b\u4f53\u7f16\u7801\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6\u3002\u8fd9\u4e2a\u53c2\u6570\u671f\u671b\u5f97\u5230\u4e00\u4e2ajava.lang.String\u7c7b\u578b\u7684\u503c\u3002\u5982\u679c\u8fd9\u4e2a\u53c2\u6570\u6ca1\u6709\u88ab\u8bbe\u7f6e\uff0c\u90a3\u4e48\u5c31\u4f7f\u7528ISO-8859-1\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.useragent'\uff1a\u5b9a\u4e49\u4e86\u5934\u90e8\u4fe1\u606fUser-Agent\u7684\u5185\u5bb9\u3002\u8fd9\u4e2a\u53c2\u6570\u671f\u671b\u5f97\u5230\u4e00\u4e2ajava.lang.String\u7c7b\u578b\u7684\u503c\u3002\u5982\u679c\u8fd9\u4e2a\u53c2\u6570\u6ca1\u6709\u88ab\u8bbe\u7f6e\uff0c\u90a3\u4e48HttpClient\u5c06\u4f1a\u4e3a\u5b83\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u503c\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.protocol.strict-transfer-encoding'\uff1a\u5b9a\u4e49\u4e86\u54cd\u5e94\u5934\u90e8\u4fe1\u606f\u4e2d\u662f\u5426\u542b\u6709\u4e00\u4e2a\u975e\u6cd5\u7684Transfer-Encoding\uff0c\u90fd\u8981\u62d2\u7edd\u6389\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.protocol.expect-continue'\uff1a\u4e3a\u5305\u542b\u65b9\u6cd5\u7684\u5b9e\u4f53\u6fc0\u6d3bExpect: 100-Continue\u63e1\u624b\u3002Expect: 100-Continue\u63e1\u624b\u7684\u76ee\u7684\u662f\u5141\u8bb8\u5ba2\u6237\u7aef\u4f7f\u7528\u8bf7\u6c42\u4f53\u53d1\u9001\u4e00\u4e2a\u8bf7\u6c42\u4fe1\u606f\u6765\u51b3\u5b9a\u6e90\u670d\u52a1\u5668\u662f\u5426\u5e0c\u671b\u5728\u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42\u4f53\u4e4b\u524d\u5f97\u5230\u8fd9\u4e2a\u8bf7\u6c42\uff08\u57fa\u4e8e\u8bf7\u6c42\u5934\u90e8\u4fe1\u606f\uff09\u3002Expect: 100-Continue\u63e1\u624b\u7684\u4f7f\u7528\u53ef\u4ee5\u5bf9\u9700\u8981\u76ee\u6807\u670d\u52a1\u5668\u8ba4\u8bc1\u7684\u5305\u542b\u8bf7\u6c42\u7684\u5b9e\u4f53\uff08\u6bd4\u5982POST\u548cPUT\uff09\u5bfc\u81f4\u660e\u663e\u7684\u6027\u80fd\u6539\u5584\u3002Expect: 100-Continue\u63e1\u624b\u5e94\u8be5\u8c28\u614e\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b83\u548cHTTP\u670d\u52a1\u5668\uff0c\u4e0d\u652f\u6301HTTP\/1.1\u534f\u8bae\u7684\u4ee3\u7406\u4f7f\u7528\u4f1a\u5f15\u8d77\u95ee\u9898\u3002\u8fd9\u4e2a\u53c2\u6570\u671f\u671b\u5f97\u5230\u4e00\u4e2ajava.lang.Boolean\u7c7b\u578b\u7684\u503c\u3002\u5982\u679c\u8fd9\u4e2a\u53c2\u6570\u6ca1\u6709\u88ab\u8bbe\u7f6e\uff0c\u90a3\u4e48HttpClient\u5c06\u4f1a\u8bd5\u56fe\u4f7f\u7528\u63e1\u624b\u3002<\/li>\n<li style=\"font-family: Verdana, Arial, Tahoma, sans-serif;\">'http.protocol.wait-for-continue'\uff1a\u5b9a\u4e49\u4e86\u5ba2\u6237\u7aef\u5e94\u8be5\u7b49\u5f85100-Continue\u54cd\u5e94\u6700\u5927\u7684\u6beb\u79d2\u7ea7\u65f6\u95f4\u95f4\u9694\u3002\u8fd9\u4e2a\u53c2\u6570\u671f\u671b\u5f97\u5230\u4e00\u4e2ajava.lang.Integer\u7c7b\u578b\u7684\u503c\u3002\u5982\u679c\u8fd9\u4e2a\u53c2\u6570\u6ca1\u6709\u88ab\u8bbe\u7f6e\uff0c\u90a3\u4e48HttpClient\u5c06\u4f1a\u5728\u6062\u590d\u8bf7\u6c42\u4f53\u4f20\u8f93\u4e4b\u524d\u4e3a\u786e\u8ba4\u7b49\u5f853\u79d2\u3002<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!--end: topics \u6587\u7ae0\u3001\u8bc4\u8bba\u5bb9\u5668--><br \/>\n\u8f6c\u81ea http:\/\/www.cnblogs.com\/loveyakamoz\/archive\/2011\/07\/21\/2112804.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u8d85\u6587\u672c\u4f20\u8f93\u534f\u8bae\uff08HTTP\uff09\u4e5f\u8bb8\u662f\u5f53\u4eca\u4e92\u8054\u7f51\u4e0a\u4f7f\u7528\u7684\u6700\u91cd\u8981\u7684\u534f\u8bae\u4e86\u3002Web\u670d\u52a1\uff0c\u6709\u7f51\u7edc\u529f\u80fd\u7684\u8bbe\u5907\u548c\u7f51\u7edc\u8ba1\u7b97\u7684\u53d1\u5c55\uff0c\u90fd\u6301\u7eed\u6269\u5c55\u4e86HTTP\u534f\u8bae\u7684\u89d2\u8272\uff0c\u8d85\u8d8a\u4e86\u7528\u6237\u4f7f\u7528\u7684Web\u6d4f\u89c8\u5668\u8303\u7574\uff0c\u540c\u65f6\uff0c\u4e5f\u589e\u52a0\u4e86\u9700&#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":[8,15,7,5,23],"class_list":["post-597","post","type-post","status-publish","format-standard","hentry","category-coding","tag-java","tag-15","tag-7","tag-5","tag-23"],"views":3109,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/597","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=597"}],"version-history":[{"count":1,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/597\/revisions"}],"predecessor-version":[{"id":598,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/597\/revisions\/598"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}