预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共13页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

Android开源项目xUtilsHttpUtils模块分析Android开源项目xUtilsHttpUtils模块分析分类:android2014-04-2020:322405人阅读评论(0)收藏举报Android网络编程HttpClientThreadSafeClientConnxUtils是github上的一个Android开源工具项目,其中HttpUtils模块是处理网络连接部分,刚好最近想整理下Android网络编程知识,今天学习下xUtils中HttpUtils.xUtils项目地址:https://github.com/wyouflf/xUtils先看看分析的时序图,了解下基本的过程1.Activity创建HttpUtils对象[java]viewplaincopyHttpUtilshttp=newHttpUtils();查看HttpUtils类的构造函数[java]viewplaincopypublicHttpUtils(){this(HttpUtils.DEFAULT_CONN_TIMEOUT);}publicHttpUtils(intconnTimeout){HttpParamsparams=newBasicHttpParams();ConnManagerParams.setTimeout(params,connTimeout);HttpConnectionParams.setSoTimeout(params,connTimeout);HttpConnectionParams.setConnectionTimeout(params,connTimeout);ConnManagerParams.setMaxConnectionsPerRoute(params,newConnPerRouteBean(10));ConnManagerParams.setMaxTotalConnections(params,10);HttpConnectionParams.setTcpNoDelay(params,true);HttpConnectionParams.setSocketBufferSize(params,1024*8);HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);SchemeRegistryschemeRegistry=newSchemeRegistry();schemeRegistry.register(newScheme("http",PlainSocketFactory.getSocketFactory(),80));schemeRegistry.register(newScheme("https",DefaultSSLSocketFactory.getSocketFactory(),443));httpClient=newDefaultHttpClient(<spanstyle="font-family:Arial,Helvetica,sans-serif;">newThreadSafeClientConnManager(params,schemeRegistry)</span>,params);httpClient.setHttpRequestRetryHandler(newRetryHandler(DEFAULT_RETRY_TIMES));httpClient.addRequestInterceptor(newHttpRequestInterceptor(){@Overridepublicvoidprocess(org.apache.http.HttpRequesthttpRequest,HttpContexthttpContext)throwsorg.apache.http.HttpException,IOException{if(!httpRequest.containsHeader(HEADER_ACCEPT_ENCODING)){httpRequest.addHeader(HEADER_ACCEPT_ENCODING,ENCODING_GZIP);}}});httpClient.addResponseInterceptor(newHttpResponseInterceptor(){@Overridepublicvoidprocess(HttpResponseresponse,HttpContexthttpContext)throwsorg.apache.http.HttpException,IOException{finalHttpEntityentity=response.getEntity()