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> 阅读详情

相关推荐

ESP32S3 Korvo2V3四通道AEC配置实战:基于AFE的回声消除优化

本文详细介绍了在ESP32S3 Korvo2V3平台上配置四通道AEC(回声消除)的实战经验。通过AFE算法优化和硬件连接调试,实现高质量回声消除,显著提升智能音箱和会议设备的语音交互体验。重点解析了四通道配置、数据格式对齐和参数调优等关键技术要点。

elastic6hunter的博客 932

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

从零构建基于ZYNQ与AD9361的SDR信号源:FPGA逻辑与射频前端的协同设计

本文详细介绍了从零开始构建基于ZYNQ与AD9361的SDR信号源的完整流程。通过解析FPGA逻辑与射频前端的协同设计,重点阐述了如何利用FPGA生成基带信号,并通过ARM处理器配置AD9361,最终实现一个可编程的2.4GHz载波信号发生器。内容涵盖硬件选型、Vivado环境搭建、AXI总线通信、LVDS接口设计及软件驱动开发,为SDR开发者提供了实用的实战指南。

weixin_29200485的博客 214

使用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的博客 6559

生成对抗网络(GAN、DCGAN、ACGAN)-----学习笔记

生成对抗网络学习笔记 生成对抗网络有两个关键结构:生成模型、判别模型。 生成模型:输入是一个服从正态分布的N维向量,利用这个N维向量生成一张图片。 判别模型:对于生成模型输出的图像判别它是不是真的图像。 生成模型和判别模型的博弈关系在于:生成模型的目的是生成让判别模型无法判别真伪的图像,而判别模型的目的是判断输入图像的真伪。 结合代码来看生成对抗网络中,生成器和判别器的训练过程: 判别模型的训...

weixin_43227526的博客 5489

高速DAC设计与实现--AD9122

目录 芯片简介: 功能配置设计 高速DAC软件驱动设计 芯片简介: AD9122 是一款双通道16位高性能数模转换器(DAC),在800MSPS工作条件下其无杂散动态范围(SFDR)高达72dBc,最高可提供1200 MSPS采样速率。 高速DAC--AD9122电路原理图 硬件设计的电路原理图如上图所示,AD9122具备针对直接变频传输应用进行优化的特性,包括复数数字调制以及增益与失调补偿。DAC输出经过优化后可直接与模拟正交调制器无缝接口,便于后期使...

独木舟216的博客 1万+

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

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

行走的snail--博客 4693

Docker部署OnlyOffice踩坑实录:解决editor.bin下载失败的3种姿势

本文详细解析了Docker部署OnlyOffice时editor.bin下载失败的常见原因,并提供了三种核心解决方案。重点剖析了容器网络配置、Nginx反向代理(特别是proxy_pass设置)以及安全策略调整,帮助开发者彻底解决静态资源加载问题,确保文档协作平台稳定运行。

weixin_29281941的博客 871

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

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

Akk 2419

莆田市C++专项选拔第一轮题4

现在小明同学想要从两堆硬币中各选择一枚硬币,使得两枚硬币的面值之和 不超过 k。不同的硬币组合,就算面值相同,也视为不同的方案。现在他把这些硬币分成了两堆,已知两堆硬币分别有 n 和 m 枚硬币。可选方案有: (1,2), (1,1), (1,1), (5,2), (5,1), (5,1),共 6 种。第一行三个整数 n, m, k,分别表示第一堆硬币的数量,第二堆硬币的数量,以及面值之和的上限。对于30%的数据,1 ≤ n , m ≤ 1000 , 1 ≤ b , c ≤ 1000。

lpstudio的博客 924

【华为机试真题 Python实现】分苹果

《华为机试真题》专栏含牛客网华为专栏、华为面经试题、华为OD机试真题。如果您在准备华为的面试,期间有想了解的可以私信我,我会尽可能帮您解答,也可以给您一些建议!本文解法非最优解(即非性能最优)。A,B两个人把苹果分为两堆,A希望按照它的计算规则等分苹果,他的计算规则是按照二进制加法计算,并且不计算走位,12+5=9(1100+0101=9), B的计算规则是十进制加法,包括正常进位,B希望在满足A的情况下获取苹果重量最多,输入苹果的数量和每个苹果重量,输出满足A的情况下获取的苹果总重量, 如果无法满足A的要

3413

Java爬虫①HttpClient

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

weixin_46083166的博客 358

TC3XX - MCAL知识点(九):PWM EB-tresos配置说明及代码浅析

脉冲宽度调制(PWM)驱动器负责提供与AUTOSAR指定的PWM信号生成相关的标准服务。PWM通道的底层定时器驱动是GTM (TOM或ATOM片)或CCU6 (T12或T13片)定时器通道。软硬件匹配关系如下:PWM直接引用的是GTM与CCU6模块,然后GTM与CCU6再关联到Port的,根据软硬件匹配关系,也能调用中断来使用,本例子没使用中断。CCU6是一个高分辨率的16位捕获和比较单元,具有特定的应用模式,主要用于交流驱动控制。特殊的工作模式支持控制无刷直流电机使用霍尔传感器或反电动势检测。

梦想技术家 2885

httpClient的使用(一)

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

fengfeng043的专栏 676

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

IDEA的使用指南

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

HttpClient入门一

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

dengjuyan2649的博客 131

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

HttpClient入门学习一

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

HiterCoder 1088

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

HttpClient总结一之基本使用

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

liaoliaoanxiao的博客 341

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、付费专栏及课程。

余额充值