HttpClient【一】

HttpClient系列-基础知识(一) 简述 今天开始介绍下Apache HttpClient 4的全面指南,从基础到高级进阶,本文是基础知识一。 (想自学习编程的小伙伴请搜索圈T社区,更多行业相关资讯更有行业相关免费视频教程。完全免费哦!) 状态码 从Http响应中得出状态码 发送Http请求后 - 我们返回一个org.apache.http.HttpResponse实例,我们可以获取到响应的状态行,并隐式地访问状态代码: respo... 阅读详情
之前见过这东西确不知道是干嘛的,后来学习了下才发现,原来它就相当于一个游览器客户端能够发出get和post请求,然后获得返回的数据。
首先新建一个java项目,然后添加所需jar包。
commons-logging-1.1.3.jar,httpclient-4.5.3.jar,httpcore-4.4.6.jar
然后就是代码的编写了,也比较简单。
package cn.sp.test01;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

public class HttpClient {
	public static void testGet() throws Exception{
//		第一步:把HttpClient使用的jar包添加到工程中。
//		第二步:创建一个HttpClient的测试类
//		第三步:创建测试方法。
//		第四步:创建一个HttpClient对象
		CloseableHttpClient httpClient = HttpClients.createDefault();
//		第五步:创建一个HttpGet对象,需要制定一个请求的url
		HttpGet get=new HttpGet("http://www.baidu.com");
//		第六步:执行请求。
		CloseableHttpResponse response=httpClient.execute(get);
//		第七步:接收返回结果。HttpEntity对象。
		HttpEntity entity=response.getEntity();
//		第八步:取响应的内容。
		String html=EntityUtils.toString(entity);
		System.out.println(html);
//		第九步:关闭response、HttpClient
		response.close();
		httpClient.close();
	}
	
	public void test01(){
		System.out.println("23232");
	}
	
	public void testPost() throws Exception{
//		第一步:创建一个httpClient对象
		CloseableHttpClient httpClient = HttpClients.createDefault();
//		第二步:创建一个HttpPost对象。需要指定一个url
		HttpPost post=new HttpPost("http://www.baidu.com");
//		第三步:创建一个list模拟表单,list中每个元素是一个NameValuePair对象
		List<NameValuePair> formList=new ArrayList<NameValuePair>();
		formList.add(new BasicNameValuePair("name","张三"));
		formList.add(new BasicNameValuePair("pass","1234"));
		
//		第四步:需要把表单包装到Entity对象中。StringEntity
		StringEntity entity=new UrlEncodedFormEntity(formList,"utf-8");
		post.setEntity(entity);
//		第五步:执行请求。
		CloseableHttpResponse response = httpClient.execute(post);
//		第六步:接收返回结果
		HttpEntity httpEntity=response.getEntity();
		String result = EntityUtils.toString(httpEntity);
		System.out.println(result);
//		第七步:关闭流。
		response.close();
		httpClient.close();
	}
	public static void main(String[] args) throws Exception {
		testGet();
	}
}
运行结果如下:
2017-03-17 22:26:24,633 DEBUG org.apache.http.client.protocol.RequestAddCookies.process() - CookieSpec selected: default
2017-03-17 22:26:24,645 DEBUG org.apache.http.client.protocol.RequestAuthCache.process() - Auth cache not set in the context
2017-03-17 22:26:24,646 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection() - Connection request: [route: {}->http://www.baidu.com:80][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
2017-03-17 22:26:24,661 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection() - Connection leased: [id: 0][route: {}->http://www.baidu.com:80][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
2017-03-17 22:26:24,663 DEBUG org.apache.http.impl.execchain.MainClientExec.execute() - Opening connection {}->http://www.baidu.com:80
2017-03-17 22:26:24,684 DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect() - Connecting to www.baidu.com/163.177.151.110:80
2017-03-17 22:26:24,714 DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect() - Connection established 36.36.13.14:10160<->163.177.151.110:80
2017-03-17 22:26:24,714 DEBUG org.apache.http.impl.execchain.MainClientExec.execute() - Executing request GET / HTTP/1.1
2017-03-17 22:26:24,714 DEBUG org.apache.http.impl.execchain.MainClientExec.execute() - Target auth state: UNCHALLENGED
2017-03-17 22:26:24,715 DEBUG org.apache.http.impl.execchain.MainClientExec.execute() - Proxy auth state: UNCHALLENGED
2017-03-17 22:26:24,717 DEBUG org.apache.http.headers.onRequestSubmitted() - http-outgoing-0 >> GET / HTTP/1.1
2017-03-17 22:26:24,717 DEBUG org.apache.http.headers.onRequestSubmitted() - http-outgoing-0 >> Host: www.baidu.com
2017-03-17 22:26:24,717 DEBUG org.apache.http.headers.onRequestSubmitted() - http-outgoing-0 >> Connection: Keep-Alive
2017-03-17 22:26:24,717 DEBUG org.apache.http.headers.onRequestSubmitted() - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.7.0_67)
2017-03-17 22:26:24,718 DEBUG org.apache.http.headers.onRequestSubmitted() - http-outgoing-0 >> Accept-Encoding: gzip,deflate
2017-03-17 22:26:24,718 DEBUG org.apache.http.wire.wire() - http-outgoing-0 >> "GET / HTTP/1.1[\r][\n]"
2017-03-17 22:26:24,718 DEBUG org.apache.http.wire.wire() - http-outgoing-0 >> "Host: www.baidu.com[\r][\n]"
2017-03-17 22:26:24,718 DEBUG org.apache.http.wire.wire() - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2017-03-17 22:26:24,719 DEBUG org.apache.http.wire.wire() - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.7.0_67)[\r][\n]"
2017-03-17 22:26:24,719 DEBUG org.apache.http.wire.wire() - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2017-03-17 22:26:24,719 DEBUG org.apache.http.wire.wire() - http-outgoing-0 >> "[\r][\n]"
2017-03-17 22:26:24,736 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]"
2017-03-17 22:26:24,736 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Server: bfe/1.0.8.18[\r][\n]"
2017-03-17 22:26:24,737 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Date: Fri, 17 Mar 2017 14:26:22 GMT[\r][\n]"
2017-03-17 22:26:24,737 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Content-Type: text/html[\r][\n]"
2017-03-17 22:26:24,737 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Last-Modified: Mon, 23 Jan 2017 13:27:41 GMT[\r][\n]"
2017-03-17 22:26:24,737 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Transfer-Encoding: chunked[\r][\n]"
2017-03-17 22:26:24,737 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Connection: Keep-Alive[\r][\n]"
2017-03-17 22:26:24,738 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform[\r][\n]"
2017-03-17 22:26:24,738 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Pragma: no-cache[\r][\n]"
2017-03-17 22:26:24,738 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/[\r][\n]"
2017-03-17 22:26:24,738 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "Content-Encoding: gzip[\r][\n]"
2017-03-17 22:26:24,738 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "[\r][\n]"
2017-03-17 22:26:24,741 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << HTTP/1.1 200 OK
2017-03-17 22:26:24,741 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Server: bfe/1.0.8.18
2017-03-17 22:26:24,741 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Date: Fri, 17 Mar 2017 14:26:22 GMT
2017-03-17 22:26:24,741 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Content-Type: text/html
2017-03-17 22:26:24,742 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Last-Modified: Mon, 23 Jan 2017 13:27:41 GMT
2017-03-17 22:26:24,742 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Transfer-Encoding: chunked
2017-03-17 22:26:24,742 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Connection: Keep-Alive
2017-03-17 22:26:24,742 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
2017-03-17 22:26:24,742 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Pragma: no-cache
2017-03-17 22:26:24,742 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
2017-03-17 22:26:24,742 DEBUG org.apache.http.headers.onResponseReceived() - http-outgoing-0 << Content-Encoding: gzip
2017-03-17 22:26:24,749 DEBUG org.apache.http.impl.execchain.MainClientExec.execute() - Connection can be kept alive indefinitely
2017-03-17 22:26:24,754 DEBUG org.apache.http.client.protocol.ResponseProcessCookies.processCookies() - Cookie accepted [BDORZ="27315", version:0, domain:baidu.com, path:/, expiry:null]
2017-03-17 22:26:24,757 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "476[\r][\n]"
2017-03-17 22:26:24,757 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x3][0x85]V[o[0xdc]D[0x14]~G[0xe2]?L[0x8d][0x92][0xb4][0x8a]v[0x9d][0xdd]U[0xd5][0x92][0xb5][0x1d][0x85]4H[0x11][0xf][0xad]h"[0xc1][0xd3]jl[0x8f][0xd7][0xd3][0xd8]3[0xc6]3^gyj[0xa4][0x16][0x81][0xa0][0x4]T.[0x82]"[0x81][0x10]4< 5[0x88]HT)i[0xff][0xcc]:[0x97]'[0xfe][0x2]g[0xec][0xd9][0xec]n[0xb2]QW+[0xd9]s[0xe6][0xcc]w[0xbe]s[0x1d][Wn[0xdd]^Y[0xff][0xf0][0xce]*[\n]"
2017-03-17 22:26:24,757 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "e[0x1c]9o[0xbe]a][0xa9][0xd5][0xee][0xae]/[0xaf]o[0xdc]E[0xb7][0xdf][0xab][0xd5][0x1c][0xab][0x94]#+$[0xd8]w[0xac][0x98]H[0xc][0x9a]2[0xa9][0x91][0x8f]2[0xda][0xb3]=[0xce]$a[0xb2]&[0xfb][0x9]AzaK[0xb2]%Mu[0xac][0xed][0x85]8[0x15]D[0xda][0x99][0xc]j7/[0x9e][0xfe][0xa0][0xb6][0xb1]\[[0xe1]q[0x82]%u[0xa3][0x11][0xc0][0xda][0xaa][0xbd][0xea]w[0x89]>0[0x84][0xc5]Q[0x8e][0xfb][0x2]1[0x1c][0x13];%[0x1]IS[0x92]:VD[0xd9]&JId[0xb][0xd9][0x8f][0x88][0x8][0x9][0x91]H[0xb1][0xa9]XxB[0xa0][0x10][0x94]m[0xc5]y[0xd1]4E[0xa3][0xee][0xfa]B[0x82]=[0xaf][0xee][0xf1][0xd8]L[0xcd]<[0xcf]M[0xf]{!1][0x9f][0xa7][0x1f][0x9b].[0xa6]~V[0x8f])[0xab][0xc3]Y[0xc7][0x92]TF[0xc4]9[0xfe][0xe1]eq[0xf0]t[0xf0][0xfc][0xfe][0xe0][0xf9][0xe7][0xff][0xfd][0xfb][0xc5][0xe0][0xf0][0x97]b[0xef][0xaf][0xe3][0x9f]?[0xdd]~l[0x99][0x95][0x8a]e[0x96][0x11]B[0x96][0xcb][0xfd]>R[0xac][0xec][0xb7][0x16][0xe0][0xe7]y[0xe][0xb2]|[0xda]C[0xd4][0xb7][0xf3][0x14]'[0x9][0x90]>[0x13][0xe8]#j[0xdb][0x8b][0xb0][0x10][0xb6][0x12]t&[0xd5][0xaa][\r][0xd1][0x9]x[0x1a][0xeb][0x93][0xe3][0xa2]s[0xda]`%[0xea][0x82][0x1a][0x8d][0xbb]([0xa4]>[0x9][0xb8][0x97][0x9][[0xa6][0x19]A"[0xf5]lS[0xf9][[0xaf]|T[0xfe][0x83][0x1a][0xf8][0xdd][0x89]x[0x97]7[0xea][0x9][0xeb][0xa2][0x9c][0xfa]2[0xb4][0x9b]7[0x16]PHh7[0x94]v[0xa3][0xf9]6[0xc0][0x99]@[0x11][0x1e][0x8a][0x83]r[0xa4]|[0x96][0x89][0x8][0x10][0xf6]$[0xe5][0xec][0x2][0xb2][0xd0][0x1e][0x5][0x8a]4eI[0xa6][0xd3][0x2][0xa4]|[0xc2][0xaa],[0x96][0x11][0xef][0x0][0xf][0x82]z8[0xca][0x88][0xdd][0xb8]\[0x97][0xe]u[0xaa]Z[0xba][0x14]3[0xd0]P7/[0x87]JE[0xaf][0xe3]&[0xaf]7[0xa9][0xf4][0xa8][0xbf][0xf5]zE[0xc9][0xb4]N[0x19]X[0xc7][0x12][0x9]f[0xda]}[0xc3][0xed]"[0xd1][0xa1][0x89][0x84]<[0x19][0x8e][0xe][0x4]Dp3[0xaf]B[0x90][0xfb]Z[0xb1]T[0xaa]`P[0x8c][0xb7]"[0xc2][0xba]*[0x11][0xd7][0xaf]#[0x9c]I[0xe]1J""[0x89][0xcd][0x3][0x88]8[0x8][0xca][0xbc]:[0x96][0xa9]LM1[0xe8]J6n[0xb0]l[0x8][0x91][0xb9]1[0x95]*}"[0xd3]|[0xc7][0xeb]z[0x82]0[0x9c][0x7][0xb6][0x15]:d_[0xd7][0x9e][0xae][0x2][0xfd][0xd0]E[0x9d][0xa9][0xa4][0xc1]P[0x18][0xeb]2Fr1*[0xb2][0xca]Qy[0xaf]#S[0xb5][0xa1][0xed][0xc4][0xc][0xf7][0x9c][0xa3][0xef][0xf6]N[0xbf]a[0x99][0xf8][0x2][0x84]*[0xd3][0x10][0xf3]F[0xb3][0xa5][0xfa]t[0xc][0xa2][0x12][0x8e][0x83]T[0x92]i 1N[0xa6][0xd2][0x0][0xf9]8@[0xf1][0xd3]^[0xf1][0xe4][0xe5]4[0x80][0xde][0xd4][0xe3]=[0xe8]+>[0xe]p[0xb2][0xfb][0xc9][0xe9][0xaf]_O[0x3][0x90][0x94][0xb8]x*H[0xb9]3[0x1][0xb2][0xbf]_|[0xb5][[0x81]0.[0xbc][0x14][0x8a]fjXF[0xdd][M,h^[0x98]V][0x1a],[0x95]o[0xb3]8N[0xda]2[0x89][0xec][0x98][0x95][0xaf]Y9[0xfb]fZ[0xcb]3[0xcd]w[0xe1]?[0xd1][0xff]3[0xcd]`[0xa6][0x15][0x8c][0xda]p[0xa6][0xe5]7[0xce]b][0xa2]i[0x86][0x91][0xb]3[0xf0]Eq[0xf8]m[0xc5][0xcf][0x1c]#[0xa8][0x99][0xfa]0hb[0xb8][\n]"
2017-03-17 22:26:24,758 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "[0xea]yJ%[0xb9]:7,[0x9]CO[0xde][0x9][0xbb]z[0xd6][0x9e]g[0xae]Yg[0xf6][0xdc]<"[0xcc][0xe3]>[0xd9]xm[0x5]J[0x9f]3@[0xbe][0x9a]S[0xe6][0xf3][0xbc][0x1e]q[0xf][0xe6]7guUr[0xf3][0xe8][0x82]X[0x10][0x9c]z![0xb2]m[0x1b][0x19][0x6]ZB[0xc6][0x92][0x81][0x16][0x91]1k\[0x9b]G[0xc6][0xc8]W[0xbb][0xa1][0x4]sF[0xe5][0xaf][0x1][0xf5]Y[0xd2]1[0xb4][0xc7]F[0xe4][0x1a]c>[0xcf]]kC;[0x9c]K[0xca][0xf9]i[0x1a][0xf3][0x94][0x98]g[0xf1]sSJ[0xe1][0xee][0xd2]x[0xb0]B[0xe5][0x15]e[0x1b]>[0x15]I[0x84][0xfb][0x8b][0xc8][0x5]W6[0xdb][0x86]s[0xf4]d[0xbf][0xf8][0xed][0xc7][0xc1][0xc1]n[0xf1]x[[0x7][0xb8][0x9a][0xb7]S[0x1b].[0x90]+[0x9c]Ae[0xe8][0xfe]+[0x97]9[0xac][0x13][0xd5][0xda]Qx[0xa1]fB[0x98][0xaf][0xa3][0x12]t[0x8a][0x87][0xf][0xe][0xbe][0xac]:Z[0xc9][0xd2]tLy[0xd9][0xe5]0[0xb8][0xdf]Qw[0xa2]&[0x96][0xc]-y[0x89]3[0xeb][0xf1][0xa4][0xdf]n.4n[0xcc]2W$[0xed]R[0xaf]z[0x1d][0xa6]j[0xf6][0xfd]L[0xf6]Mgp[0xf8][0xea][0xf8][0x9b]?*"[0xc5]g[0x8f][0x8a]W[0xf]O[0x9e][0x95][0xb3][0xa0]B8?T[0xee]Q[0xcc][0xfa]t[0xc4][0xcd][0xd4][0x81][0xf5][0x92]Z@[0x88][0xef]bo[0xd3]9z[0xb0]s[0xb2][0xbb]][0xec]<:}[0xfa][0xa9][0xe2][![\r][0xe][0xfe]\[[0xb9]s[0xf2]l{[0xa1][0x5]T[[0xc5][0xce]?C[0xb][0xea][0x96][0xbc][0xec]Z[0xec][\n]"
2017-03-17 22:26:24,758 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "[0xd5]S[0xe0][0xad][0xa9]\[0x9e][0xcc][0xc4]p[0xa5][0xee]z[0xb5][0xa9][0xbf][0x9d][0xfe][0x7]\[0x85]C[0x1]M[0x9][0x0][0x0][\r][\n]"
2017-03-17 22:26:24,758 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "0[\r][\n]"
2017-03-17 22:26:24,758 DEBUG org.apache.http.wire.wire() - http-outgoing-0 << "[\r][\n]"
2017-03-17 22:26:24,759 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager.releaseConnection() - Connection [id: 0][route: {}->http://www.baidu.com:80] can be kept alive indefinitely
2017-03-17 22:26:24,759 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager.releaseConnection() - Connection released: [id: 0][route: {}->http://www.baidu.com:80][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a>  <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> äº¬ICP证030173号  <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

2017-03-17 22:26:24,760 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager.shutdown() - Connection manager is shutting down
2017-03-17 22:26:24,760 DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection.close() - http-outgoing-0: Close connection
2017-03-17 22:26:24,760 DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager.shutdown() - Connection manager shut down
下一期再写在项目中的运用。

爬虫HttpClient 一 1.hello world 环境准备 JDK1.8 IntelliJ IDEA DEA自带的Maven 1.1 导入 pom.xml <dependencies> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <!-- HttpClient --> <dependency> 阅读详情

相关推荐

Anchor graph 对齐文献解读

Align then Fusion: Generalized Large-scale Multi-view Clustering with Anchor Matching Correspondences文献解读

atease0001的博客 1167

Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory

代码: CloseableHttpClient httpclient = HttpClients.createDefault(); 报错,错误提示如下: java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFa...

datouniao1的博客 6896

Gromacs实战:从蛋白质-小分子对接到分子动力学模拟全流程解析

本文详细解析了使用Gromacs进行蛋白质-小分子复合物分子动力学模拟的全流程。从处理AutoDock等对接软件的结果文件开始,逐步指导如何为蛋白质和小分子分别生成拓扑文件,并解决力场合并的核心挑战。文章涵盖了构建模拟盒子、添加溶剂离子、能量最小化、平衡模拟以及关键的轨迹分析步骤,为计算生物学和药物设计研究者提供了一套从静态对接到动态评估的完整实战指南。

weixin_29251337的博客 1222

使用Solr进行添加时报错的解决方式

DEBUG [main] - Creating new http client, config:maxConnections=128&maxConnectionsPerHost=32&followRedirects=false DEBUG [main] - Connection request: [route: {}->http://localhost:8055][total kept aliv

LazyTojava的博客 6560

机器人视觉实战:用OpenCV搞定手眼标定(附完整C++代码)

本文详细介绍了使用OpenCV实现机器人视觉中的手眼标定技术,包括核心算法、工业场景优化及完整C++代码示例。通过解析坐标系转换问题,提供从数据采集到标定验证的全流程解决方案,帮助开发者在复杂工业环境中实现高精度机械臂与视觉系统的协同作业。

weixin_29306571的博客 487

HTML5期末大作业:水果超市网站设计——水果超市(6页) HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 网购商城设置网页

HTML5期末大作业:水果超市网站设计——水果超市(6页) HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 网购商城设置网页 常见网页设计作业题材有 个人、 美食、 公司、 学校、 旅游、 电商、 宠物、 电器、 茶叶、 家居、 酒店、 舞蹈、 动漫、 明星、 服装、 体育、 化妆品、 物流、 环保、 书籍、 婚纱、 军事、 游戏、 节日、 戒烟、 电影、 摄影、 文化、 家乡、 鲜花、 礼品、 汽车、 其他 等网页设计题目, A+水平作业, 可满足大

1718

异常:ClassNotFoundException: org.apache.http.client.config.RequestConfign Could not initialize class

ClassNotFoundException 编辑 无法找到指定的类异常 出现这个问题一般就有点懵了,其实问题很明显,和你jar包的引入有很大关系。可以从以下几点来解决问题 1、首先在项目文件中没有添加相应的jar包,可以在maven dependencis文件夹中看是否有(其实这个包如果没有项目会报错,一般来说不会还是这样) 2、很有可能存在jar包版本问题,把xml中依赖的jar包版本换...

行走的snail--博客 4694

Android GNSS 可视卫星星空图/卫星天顶图 原理及画法介绍

目录1 概念介绍2 绘制步骤2.1 获取卫星信息2.2 绘制底图 效果图: 1 概念介绍 首先介绍一下方位角和高度角的概念: 方位角:是从某点的指北(地理北极)方向线起,依顺时针方向到目标方向线之间的水平夹角。 高度角:从一点至观测目标的方向线与水平面间的夹角。 卫星天顶图 即是根据每一颗卫星的方位角和高度角将其画在以观测位置为中心的天顶图上。 天顶图其底图为由外向内的三个圆和四条直线。三个圆由外向内依次代表高度角0°、30°、60°,中心点代表90°;四条直线分别表示正北-正南、东北-西南、正东

x1471898145的博客 1万+

HttpClient详解(一)—简介与请求

简介 首先说说HttpClient和Http的关系:   我们知道HTTP是一个客户端和服务器端请求和应答的标准(TCP)。   我们通常发起http请求时都在客户端通过get或post的方式发起(项目中最常用的即通过Ajax实现)。   不仅如此,在服务端java.net包提供了基本通过HTTP访问资源的功能,但它没有提供全面的灵活性和其它很多应用程序需要的 功能。   Ht

Akk 2419

SPSS中的数据分析—信度效度检验【1】

前一段时间跟大家分享了好几篇关于EXCEL方面的数据分析知识,不知道大家都掌握得怎么样了。今天咱们换个口味,给大家讲一下关于SPSS中的数据分析——信度效度检验。 现阶段正处在毕业季阶段,很多同学可能都正在忙着去弄自己的论文和答辩(不知道大家在翟天临上热搜这个事情上有没有做出过一定贡献),很多时候我们在写论文答辩甚至于其他课题研究的时候都会选择用问卷这种形式来收集数据。最后我们只需要针对问卷所取...

小白数据营的博客 6万+

SAP 系统升级不再惧怕 SPAU 与 SPDD:把修改调整做成可控的工程

SAP系统升级中的SPAU/SPDD处理要点:首先明确SPDD处理数据字典对象,SPAU处理程序对象,核心是解决标准对象变更与历史修改的继承问题。关键原则是优先回归标准版本,减少后续升级负担。操作时应利用版本管理对比差异,批量处理可回退对象,并通过F9多选提高效率。对于提示"当前版本与建议一致"的对象直接回归标准。注意区分新旧SPAU界面功能差异,将Note下载移至SNOTE处理,并确保在SPDD/SPAU之后处理SPAU_ENH。最后,所有调整需记录日志并纳入传输请求,确保可追溯性。遵

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 404

Java爬虫①HttpClient

HttpClient是Apache中一个开源的项目,用来提供高效的,最新的,功能丰富的支持HTTP协议的客户端编程工具包,并且它支持HTTP协议最新版本和建议。 引入依赖 <dependencies> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifact

weixin_46083166的博客 359

Redhawk: 为什么STA CHECK中switch cell覆盖率为0(STA file中switch control pin没有timing window)?

如题,做dynamic analysis时,不需要switch cell的timing window信息,但是做low power analysis需要做上电时switch cell的timing window就是必须的了,本文对switch cell control pin没有timing window (STA CHECK覆盖率为零)的这种现象做分析。

m0_61544122的博客 1206

httpClient的使用(一)

1、是什么? 是客户端编程工具包。 可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包 ---------------------- 2、有什么用? 一句话:用它来发送和接收HTTP报文。 越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源 HttpClient 提供的主要的功能: (1)实现了所有 HTTP 的方法(GET,POST

fengfeng043的专栏 676

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

HttpClient入门一

HttpClient是一个实现了Http协议的功能强大的编程工具包。 要使用HttpClient,通常需要以下几部: 1、常见一个HttpClient实例 2、创建一个get或者post方法 3、告诉HttpClient去执行获取的方法 4、读取服务器的响应 5、释放连接 6、处理响应的内容 下面这个实例就实现了一个从指定网页去读取网页内容的代码。 ...

dengjuyan2649的博客 132

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

HttpClient入门学习一

1、HttpClient 是Apache Jakarta Common 下的子项目,可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 HTTP 协议最新的版本和建议。   虽然在 JDK 的 java net包中已经提供了访问 HTTP 协议的基本功能,但是对于大部分应用程序来说,JDK 库本身提供的功能还不够丰富和灵活。HttpClient 是 ...

HiterCoder 1089

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

HttpClient总结一之基本使用

文章出处:https://www.cnblogs.com/LuckyBao/p/6096145.html 最近工作中是做了一个handoop的hdfs系统的文件浏览器的功能,是利用webhdfs提供的rest api来访问hdfs来与hdfs进行交互的,其中大量使用HttpClient,之前一直很忙,没什么时间来总结,今天闲下来了,可以来好好总结一下这个东西了。 1.HttpClient简介...

liaoliaoanxiao的博客 342

httpclient妙用一 httpclient作为客户端调用webservice

httpclient妙用一 httpclient作为客户端调用webservice http://aperise.iteye.com/blog/2223454 httpclient妙用二 httpclient保持会话登录 http://aperise.iteye.com/blog/2223470 httpclient连接池 http://aperise

猿类崛起 3万+

httpclient(一)

httpclient是apache封装的用于http请求的工具包,和python的requests类似。这里介绍一些简单功能的使用。后续根据需求也会慢慢扩展 使用HttpClient请求一个Http请求的步骤为: (1)创建一个HttpClient对象模拟浏览器操作   CloseableHttpClient httpclient = HttpClients.createDefault(...

weixin_30885111的博客 167

HttpClient(一)

简介:HTTP 协议可能是现在 Internet 上使用得最多、最重要的协议了,越来越多的 Java应用程序需要直接通过 HTTP 协议来访问网络资源。虽然在 JDK 的 java net包中已经提供了访问 HTTP 协议的基本功能,但是对于大部分应用程序来说,JDK 库本身提供的功能还不够丰富和灵活。HttpClient 是 Apache Jakarta Common 下的子项目...

dengliru4372的博客 70

【HttpClient】HttpClient总结一之基本使用

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33798152的博客 230
上一篇: 线程死锁问题
下一篇: JVM【一】
2YSP
博客等级 码龄10年 12粉丝 34原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址