HttpComponents??????????
???????????? ???????[ 2012/11/26 10:37:29 ] ????????
????return result;
????}
????/**
????* @param uri
????* @param nameValuePairs
????* @return
????*/
????public static PostMethod createPostMethod(String uri?? NameValuePair[] nameValuePairs) {
????PostMethod method = new PostMethod(uri);
????method.addParameters(nameValuePairs);
????method.getParams().setContentCharset(charsetName);
????return method;
????}
????/**
????* @param uri
????* @param nameValuePairs
????* @return
????*/
????public static GetMethod createGetMethod(String uri?? NameValuePair[] nameValuePairs) {
????GetMethod method = new GetMethod(uri);
????List list = Lists.newArrayList();
????if (nameValuePairs != null) {
????Collections.addAll(list?? nameValuePairs);
????method.setQueryString(list.toArray(new NameValuePair[nameValuePairs.length]));
????}
????method.getParams().setContentCharset(charsetName);
????return method;
????}
????public static HttpClient createHttpClient() {
????//1.
????HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
????//2.
????HttpConnectionManagerParams httpConnectionManagerParams = httpClient
????.getHttpConnectionManager().getParams();
????httpConnectionManagerParams.setConnectionTimeout(connectionTimeout);
????httpConnectionManagerParams.setTcpNoDelay(true);//Nagle's algorithm
????httpConnectionManagerParams.setSoTimeout(timeOut);
????httpConnectionManagerParams.setDefaultMaxConnectionsPerHost(maxHostConnections);
????httpConnectionManagerParams.setMaxTotalConnections(maxTotalConnections);
????//3.
????HttpClientParams httpClientParam = httpClient.getParams();
????//httpClientParam.setConnectionManagerTimeout(connectionTimeout);//????????????????????????????????????
????httpClientParam.setParameter(HttpMethodParams.RETRY_HANDLER??
????new DefaultHttpMethodRetryHandler(retryCount?? false));
????httpClientParam.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
????return httpClient;
????}
????public static JSONObject doGet(String url?? NameValuePair[] params) {
????return executeMethod(createHttpClient()?? createGetMethod(url?? params));
????}
????public static JSONObject doPost(String url?? NameValuePair[] params) {
????return executeMethod(createHttpClient()?? createPostMethod(url?? params));
????}
????protected HttpClientUtils() {
????}
????public void setTimeOut(int timeOut) {
????HttpClientUtils.timeOut = timeOut;
????}
????public static int getTimeOut() {
????return timeOut;
????}
????public static int getRetryCount() {
????return retryCount;
????}
????public void setRetryCount(int retryCount) {
????HttpClientUtils.retryCount = retryCount;
????}
????public static int getConnectionTimeout() {
????return connectionTimeout;
????}
????public void setConnectionTimeout(int connectionTimeout) {
????HttpClientUtils.connectionTimeout = connectionTimeout;
????}
????public static int getMaxHostConnections() {
????return maxHostConnections;
????}
????public void setMaxHostConnections(int maxHostConnections) {
????HttpClientUtils.maxHostConnections = maxHostConnections;
????}
????public static int getMaxTotalConnections() {
????return maxTotalConnections;
????}
????public void setMaxTotalConnections(int maxTotalConnections) {
????HttpClientUtils.maxTotalConnections = maxTotalConnections;
????}
????public static String getCharsetName() {
????return charsetName;
????}
????public void setCharsetName(String charsetName) {
????HttpClientUtils.charsetName = charsetName;
????}
????}
???????????????????????????????????httpClient?????????????????Щ????ɡ????????????????????????????????棺
????(1)????????????????finally??collection????????????????????????????????????????????????????????????????;
????(2)Retry?????ж???????????????????httpClient4?У?put??post??????δ????http?淶???£??????????????;
????(3)SSL??TLS??????????;
????(4)?????????????????????Concurrency in practice?е????annotation????????????????????????????SureLogic?????????license????????????apache?????????developer?;
????(5)????????header?????;
????(6)collection stale check????;
????(7)Cookie specification choose??????????????;
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11