【androidx86 5.1.1】Android HttpClient请求过程解析(上)

Android实现HTTPS请求的HttpClient编程 在Android 6.0及以上的版本中,系统不再默认支持使用HttpClient,所以我们需要使用HttpClient Android库提供的兼容版。值得注意的是,在Android 9及以上的版本中,默认不允许在主线程中进行网络请求,所以在实际开发中,建议将网络请求放在异步任务或者单独的线程中进行。通过以上步骤,我们可以在Android应用程序中使用HttpClient库来实现HTTPS请求。以上代码中,我们使用HttpGet对象来创建一个GET请求,发送给指定的URL。 阅读详情

Android HttpClient请求过程解析

前言:很久没有写源码解析相关的文章了,所谓“三天不写,上房揭瓦”,这都仨月啦!前段时间忙着发版,经理有别的事情忙,就把管理发版的事情丢给我了,这事确实很麻烦啊,要关注的人事物都很多,虽然对于技术的提升很小,不过也加深了我对整个产品的理解和视野的开阔,对于时间安排与发展规划都有了更深的理解。每次的前言都是自己胡说八道的废话。好了,言归正传,这次的博客就是对于android的HttpClient进行请求数据的流程解析。

 

综述

总体来说http请求包括三个步骤,分别是域名解析、建立连接、发送请求。

首先写一个简单的HttpClient请求的android代码。

 

       HttpClienthttpClient = new DefaultHttpClient();//1、获取默认客户端

       HttpGethttpGet = new HttpGet(“http://www.baidu.com/”); //2、创建HttpGet请求

       try{

              HttpResponseresponse = httpClient.execute(httpGet);//3、通过客户端发送请求获取数据

       }catch (Exception e) {

              e.printStackTrace();

       }

 

 

 

二、获取默认客户端

首先创建了一个默认的httpClient,其中的调用流程如下:

1、创建DefaultHttpClient对象,其代码位于external\apache-http\src\org\apache\http\impl\client\DefaultHttpClient.java

public DefaultHttpClient() {

super(null,null);

}

 

2、调用父类,进行构造函数,代码位于external\apache-http\src\org\apache\http\impl\client\AbstractHttpClient.java

/**

    * Creates a new HTTP client.

    *

    * @param conman    the connectionmanager

    * @param params    the parameters

    */

   protected AbstractHttpClient(

           final ClientConnectionManager conman,

           final HttpParams params) {

       defaultParams        = params;

       connManager          = conman;

} // constructor

好的,这里构造了一个空的HttpClient对象

 

三、创建HttpGet请求

然后创建了一个HttpGet请求,其中的调用流程如下:

1、创建HttpGet对象,其代码位于external\apache-http\src\org\apache\http\client\methods\HttpGet.java

/**

* @throws IllegalArgumentException if theuri is invalid.      

*/

public HttpGet(final String uri) {

super();

setURI(URI.create(uri));

}

2、父类位于external\apache-http\src\org\apache\http\client\methods\HttpRequestBase.java

public HttpRequestBase() {

super();

this.abortLock =new ReentrantLock();

}

3、父类的父类位于external\apache-http\src\org\apache\http\message\AbstractHttpMessage.java

protected AbstractHttpMessage(finalHttpParams params) {

       super();

       this.headergroup = new HeaderGroup();

       this.params = params;

    }

 

   protected AbstractHttpMessage() {

       this(null);

    }

四、通过客户端发送请求获取数据

放流程图

然后开始正式的解析并获取数据

1、 执行我们看到的execute函数,其代码位于src\org\apache\http\impl\client\AbstractHttpClient.java’

其通过两次调用重载的重名函数,跳到了

       publicfinal HttpResponse execute(HttpUriRequest request,

                                     HttpContext context)

       throws IOException, ClientProtocolException {

 

       if (request == null) {

           throw new IllegalArgumentException

                ("Request must not benull.");

       }

 

       returnexecute(determineTarget(request), request, context);

}

没啥可说的,首先判断了request的null异常,就再次进行了内部跳转,其中有一个determineTarget函数

private HttpHostdetermineTarget(HttpUriRequest request) {

        // A null target may be acceptable ifthere is a default target.

        // Otherwise, the null target isdetected in the director.

        HttpHost target = null;

 

        URI requestURI = request.getURI();

              //如果URI可以获取到请求类型,则直接新建HttpHost

        if (requestURI.isAbsolute()) {

            target = new HttpHost(

                    requestURI.getHost(),

                    requestURI.getPort(),

                    requestURI.getScheme());

        }

        return target;

    }

2、 接下来依然是调用了不同参数的execute函数

// non-javadoc,see interface HttpClient

    public final HttpResponse execute(HttpHosttarget, HttpRequest request,

                                     HttpContext context)

        throws IOException,ClientProtocolException {

 

        if (request == null) {

            throw new IllegalArgumentException

                ("Request must not benull.");

        }

        // a null target may be acceptable,this depends on the route planner

        // a null context is acceptable,default context created below

 

        HttpContext execContext = null;

        RequestDirector director = null;

       

        // Initialize the request executioncontext making copies of

        // all shared objects that arepotentially threading unsafe.

        synchronized (this) {

 

            HttpContext defaultContext =createHttpContext();

            if (context == null) {

                execContext = defaultContext;

            } else {

                execContext = newDefaultedHttpContext(context, defaultContext);

            }

            // Create a director for thisrequest

            director =createClientRequestDirector(

                    getRequestExecutor(),

                    getConnectionManager(),

                   getConnectionReuseStrategy(),

                   getConnectionKeepAliveStrategy(),

                    getRoutePlanner(),

                    getHttpProcessor().copy(),

                   getHttpRequestRetryHandler(),

                    getRedirectHandler(),

                    getTargetAuthenticationHandler(),

                   getProxyAuthenticationHandler(),

                    getUserTokenHandler(),

                    determineParams(request));

        }

 

        try {

            return director.execute(target,request, execContext);

        } catch(HttpException httpException) {

            throw newClientProtocolException(httpException);

        }

} // execute

这个函数比较长,其实主要也就三步,第一步创建一个http信息上下文HttpContext,第二步创建一个对于请求的操作者RequestDirector,第三部通过RequestDirector执行请求。RequestDirector的参数比较多,这里先不一一分析,将他的create函数放上来:

       protectedRequestDirector createClientRequestDirector(

           final HttpRequestExecutor requestExec,

           final ClientConnectionManager conman,

           final ConnectionReuseStrategy reustrat,

           final ConnectionKeepAliveStrategy kastrat,

           final HttpRoutePlanner rouplan,

           final HttpProcessor httpProcessor,

           final HttpRequestRetryHandler retryHandler,

           final RedirectHandler redirectHandler,

            final AuthenticationHandlertargetAuthHandler,

           final AuthenticationHandler proxyAuthHandler,

           final UserTokenHandler stateHandler,

           final HttpParams params) {

       return new DefaultRequestDirector(

               requestExec,

                conman,

                reustrat,

                kastrat,

                rouplan,

                httpProcessor,

                retryHandler,

                redirectHandler,

                targetAuthHandler,

               proxyAuthHandler,

                stateHandler,

                params);

    }

3、 执行RequestDirector的execute函数,相关代码文件位于src\org\apache\http\client\ RequestDirector.java

实际上调用了DefaultRequestDirector的execute函数,其位置位于src\org\apache\http\impl\client\DefaultRequestDirector.java

首先贴出代码,非常巨大的一个函数:

  // non-javadoc, see interfaceClientRequestDirector

    public HttpResponse execute(HttpHosttarget, HttpRequest request,

                                HttpContextcontext)

        throws HttpException, IOException {

       

        HttpRequest orig = request;

        //打包请求

        RequestWrapper origWrapper = wrapRequest(orig);

        //设置参数

        origWrapper.setParams(params);

        //路由定向,不管是做为本地路由还是中转路由

        HttpRoute origRoute =determineRoute(target, origWrapper, context);

 

        RoutedRequest roureq = newRoutedRequest(origWrapper, origRoute);

 

        long timeout =ConnManagerParams.getTimeout(params);

       

        int execCount = 0;

       

        boolean reuse = false;

        HttpResponse response = null;

        boolean done = false;

        try {

            while (!done) {

                // In this loop, theRoutedRequest may be replaced by a

                // followup request and route.The request and route passed

                // in the method arguments willbe replaced. The original

                // request is still availablein 'orig'.

 

                RequestWrapper wrapper =roureq.getRequest();

                HttpRoute route =roureq.getRoute();

               

                // See if we have a user tokenbound to the execution context

                Object userToken = context.getAttribute(ClientContext.USER_TOKEN);

               

                // Allocate connection ifneeded

                if (managedConn == null) {

                    ClientConnectionRequestconnRequest = connManager.requestConnection(

                            route, userToken);

                    if (orig instanceofAbortableHttpRequest) {

                        ((AbortableHttpRequest)orig).setConnectionRequest(connRequest);

                    }

                   

                    try {

                        managedConn =connRequest.getConnection(timeout, TimeUnit.MILLISECONDS);

                    }catch(InterruptedException interrupted) {

                        InterruptedIOExceptioniox = new InterruptedIOException();

                        iox.initCause(interrupted);

                        throw iox;

                    }

                            

                             //如果提交检查前需要测试是否可用,则在android当中先关闭连接

                    if(HttpConnectionParams.isStaleCheckingEnabled(params)) {

                        // validate connection

                       this.log.debug("Stale connection check");

                        if(managedConn.isStale()) {

                           this.log.debug("Stale connection detected");

                            // BEGINandroid-changed

                            try {

                               managedConn.close();

                            } catch(IOException ignored) {

                                // SSLSocket'swill throw IOException

                                // because theycan't send a "close

                                // notify"protocol message to the

                                // server. Justsupresss any

                                // exceptionsrelated to closing the

                                // stale connection.

                            }

                            // ENDandroid-changed

                        }

                    }

                }

 

                if (orig instanceofAbortableHttpRequest) {

                    ((AbortableHttpRequest)orig).setReleaseTrigger(managedConn);

                }

 

                // Reopen connection if needed

                if (!managedConn.isOpen()) {

                    managedConn.open(route,context, params);

                }

                // BEGIN android-added

                else {

                    // b/3241899 set the perrequest timeout parameter on reused connections

                   managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));

                }

                // END android-added

               

                try {

                             //建立路由跳转连接

                    establishRoute(route,context);

                } catch (TunnelRefusedExceptionex) {

                    if(this.log.isDebugEnabled()) {

                       this.log.debug(ex.getMessage());

                    }

                    response =ex.getResponse();

                    break;

                }

 

                // Reset headers on the requestwrapper

                wrapper.resetHeaders();

               

                // Re-write request URI ifneeded

                rewriteRequestURI(wrapper,route);

 

                // Use virtual host if set

                target = (HttpHost)wrapper.getParams().getParameter(

                        ClientPNames.VIRTUAL_HOST);

 

                if (target == null) {

                    target =route.getTargetHost();

                }

 

                HttpHost proxy =route.getProxyHost();

 

                // Populate the executioncontext

               context.setAttribute(ExecutionContext.HTTP_TARGET_HOST,

                        target);

               context.setAttribute(ExecutionContext.HTTP_PROXY_HOST,

                        proxy);

               context.setAttribute(ExecutionContext.HTTP_CONNECTION,

                        managedConn);

               context.setAttribute(ClientContext.TARGET_AUTH_STATE,

                        targetAuthState);

                context.setAttribute(ClientContext.PROXY_AUTH_STATE,

                        proxyAuthState);

               

                // Run request protocolinterceptors

                requestExec.preProcess(wrapper,httpProcessor, context);

               

                context.setAttribute(ExecutionContext.HTTP_REQUEST,

                        wrapper);

 

                boolean retrying = true;

                while (retrying) {

                    // Increment total execcount (with redirects)

                    execCount++;

                    // Increment exec count forthis particular request

                   wrapper.incrementExecCount();

                    if (wrapper.getExecCount()> 1 && !wrapper.isRepeatable()) {

                        throw newNonRepeatableRequestException("Cannot retry request " +

                                "with anon-repeatable request entity");

                    }

                   

                    try {

                        if(this.log.isDebugEnabled()) {

                           this.log.debug("Attempt " + execCount + " to executerequest");

                        }

                                    //执行请求

                        response =requestExec.execute(wrapper, managedConn, context);

                        retrying = false;

                       

                    } catch (IOException ex) {

                       this.log.debug("Closing the connection.");

                        managedConn.close();

                        if(retryHandler.retryRequest(ex, execCount, context)) {

                            if(this.log.isInfoEnabled()) {

                               this.log.info("I/O exception ("+ ex.getClass().getName() +

                                        ")caught when processing request: "

                                        + ex.getMessage());

                            }

                            if(this.log.isDebugEnabled()) {

                               this.log.debug(ex.getMessage(), ex);

                            }

                            this.log.info("Retryingrequest");

                        } else {

                            throw ex;

                        }

 

                        // If we have a directroute to the target host

                        // just re-open connectionand re-try the request

                        if (route.getHopCount()== 1) {

                           this.log.debug("Reopening the direct connection.");

                           managedConn.open(route, context, params);

                        } else {

                            // otherwise giveup

                            throw ex;

                        }

                       

                    }

 

                }

 

                // Run response protocol interceptors

                response.setParams(params);

               requestExec.postProcess(response, httpProcessor, context);

               

 

                // The connection is in or canbe brought to a re-usable state.

                      // 是否是一个长连接

                reuse = reuseStrategy.keepAlive(response,context);

                if(reuse) {

                    // Set the idle duration ofthis connection

                    long duration =keepAliveStrategy.getKeepAliveDuration(response, context);

                    managedConn.setIdleDuration(duration,TimeUnit.MILLISECONDS);

                }

               

                RoutedRequest followup =handleResponse(roureq, response, context);

                if (followup == null) {

                    done = true;

                } else {

                    if (reuse) {

                       this.log.debug("Connection kept alive");

                        // Make sure theresponse body is fully consumed, if present

                        HttpEntity entity =response.getEntity();

                        if (entity != null) {

                           entity.consumeContent();

                        }

                        // entity consumedabove is not an auto-release entity,

                        // need to mark theconnection re-usable explicitly

                       managedConn.markReusable();

                    } else {

                        managedConn.close();

                    }

                    // check if we can use the same connectionfor the followup

                    if(!followup.getRoute().equals(roureq.getRoute())) {

                        releaseConnection();

                    }

                    roureq = followup;

                }

               

                userToken =this.userTokenHandler.getUserToken(context);

               context.setAttribute(ClientContext.USER_TOKEN, userToken);

                if (managedConn != null) {

                    managedConn.setState(userToken);

                }

            } // while not done

 

 

            // check for entity, releaseconnection if possible

            if ((response == null) ||(response.getEntity() == null) ||

               !response.getEntity().isStreaming()) {

                // connection not needed and(assumed to be) in re-usable state

                if (reuse)

                    managedConn.markReusable();

                releaseConnection();

            } else {

                // install an auto-release entity

                HttpEntity entity =response.getEntity();

                entity = newBasicManagedEntity(entity, managedConn, reuse);

                response.setEntity(entity);

            }

 

            return response;

           

        } catch (HttpException ex) {

            abortConnection();

            throw ex;

        } catch (IOException ex) {

            abortConnection();

            throw ex;

        } catch (RuntimeException ex) {

            abortConnection();

            throw ex;

        }

    } // execute

4、未完待续

 

基于android的wifi热点的局域网通讯仿飞鸽 立即下载

相关推荐

深交所 vs 上交所:Level-2实时数据推送规则详解与策略适配指南

本文深度解析沪深Level-2实时数据推送规则的关键差异,包括逐笔成交、逐笔委托和10档行情接口的处理逻辑。针对高频交易策略,详细对比上交所与深交所在数据推送机制、时间戳处理及委托队列解析等方面的差异,并提供具体的策略适配方案和性能优化建议,帮助量化投资者提升跨市场交易稳定性。

weixin_27310417的博客 1165

Android之HttpClient的详解

——HttpClient        android5.0之前常用        android5.0之后,被HttpURLConnecetion替代        android6.0完全被舍弃        HttpClient是Apache提供的Http网络访问接口。完成的功能和HttpURLConnection几乎一模一样的效果,但两者的用法有很大的差别。       在一般情

重心开始,重新开始 2376

实战分享:如何用YOLOv5s+BIFPN高效检测隧道裂缝(附数据集获取)

本文详细介绍了如何利用YOLOv5s结合BIFPN(双向特征金字塔网络)构建高效的隧道裂缝智能检测系统。文章从高质量数据集构建、针对性数据增强、模型架构选型与调优,到工程化部署全链路进行了实战分享,旨在为基础设施自动化巡检提供兼顾精度与速度的解决方案。

weixin_29062823的博客 380

Android 之 HTTP请求方式:HttpClient

HttpClient 用于接收/发送Http请求/响应,但不缓存服务器响应,不执行HTML页面潜入的JS代码,不会对页面内容 进行任何解析,处理!其实关于HttpClient的例子有很多,比如笔者曾经用它来抓学校教务系统上学生的课程表: 这就涉及到Cookie,模拟登陆的东西,说到抓数据(爬虫),一般我们是搭配着JSoup来解析 抓到数据的,有兴趣可以自己查阅相关资料,这里贴下笔者毕设app里获取网页部分的关键 代码!// 获取响应的cookie值。// 设置Post提交的头信息的参数。

leyang0910的博客 1001

matlab特征提取和分类_SAST Weekly|MATLAB机器学习初探——做个心音分类器

SAST weekly 是由电子工程系学生科协推出的科技系列推送,内容涵盖信息领域技术科普、研究前沿热点介绍、科技新闻跟进探索等多个方面,帮助同学们增长姿势,开拓眼界,每周更新,欢迎关注!欢迎愿意分享知识的同学投稿至 eesast@mail.tsinghua.edu.cn , 期待你的作品!本期的SAST weekly,想跟大家分享一下如何用MATLAB进行初步的机器学习,构建一个正常/...

weixin_36453829的博客 5579

手把手教你用周立功USBCANFD-200U和ZCANPRO软件,从驱动安装到UDS诊断一条龙搞定

本文详细介绍了如何使用周立功USBCANFD-200U硬件和ZCANPRO软件,从驱动安装到UDS诊断的全流程操作指南。涵盖硬件连接、软件配置、CAN通信测试及UDS诊断实战,帮助汽车电子爱好者和工程师快速掌握CAN总线通信技术,实现专业的车辆诊断功能。

weixin_30752699的博客 579

Android HTTP协议请求网络(二)之HttpClient方式

 Android HTTP协议请求网络(一)之认识探索Android HTTP协议请求网络(三)之HttpURLConnection方式githup练习demo地址:https://github.com/aiyangtianci/NetworkRequestDemo一、基础介绍:1、HttpClient是Apache开源组织提供的HTTP网络访问接口(一个开源的项目),从名字上就可以看出,它是一个...

csdn_aiyang的博客 5321

ROS自定义地图实战:从CAD到导航的完整流程

本文详细介绍了如何将CAD图纸或手绘草图高效转换为ROS机器人可直接使用的导航地图。通过解析PGM与YAML标准格式,提供从图像处理、尺度校准到集成AMCL与move_base导航栈的完整实战流程,帮助开发者跳过繁琐的SLAM建图,实现快速、精准的自定义地图部署。

weixin_29083475的博客 496

Android --- 网络请求

通常在 Android 中进行网络连接一般使用 Scoket 和HTTP,HTTP 请求方式比 Scoket 多。HTTP 请求一般采用原生的 HttpClient 和 HttpUrlConnection 的两种网络访问方式(系统自带的)。

weixin_43244083的博客 2447

FreeModbus源码详解

本篇按照FreeModbus协议栈的工作流程,对源代码进行总结解析;FreeModbus协议栈作为从机,等待主机传送的数据,当从机接收到一帧完整的报文后,对报文进行解析,然后响应主机,发送报文给主机,实现主机和从机之间的通信; 1:demo.c中三个函数,完成协议栈的准备工作; eMBInit()函数:(mb.c) /*函数功能: *1:实现RTU模式和ASCALL模式的协议栈初始化; *2

2万+

Matlab编码转换实战:从GBK到UTF-8的完整解决方案

本文提供Matlab编码转换的完整实战方案,重点解决GBK与UTF-8编码冲突导致的中文乱码问题。通过修改系统配置文件、批量转换项目文件及设置默认保存编码,实现从GBK到UTF-8的彻底迁移,并分享常见避坑指南与自动化脚本技巧,确保代码跨平台协作的稳定性。

weixin_29031057的博客 325

【androidx86 5.1.1】Android HttpClient请求过程解析(下)

接上一篇: 【androidx86 5.1.1】Android HttpClient请求过程解析(下) 4、继续调用HttpRequestExecutor的execute函数,其代码位置位于external\apache-http\src\org\apache\http\protocol\HttpRequestExecutor.java /**     * Synchronou

Don't worry,be happy 1233

2025华为OD面试手撕代码真题目录及面试八股文

本专栏更新每年华为OD机试的高频手撕代码题,每个题目都会使用五种语言进行解答(C & C++& Java & Python & JS) 华为od机试,华为od机试真题,华为od机试E卷,华为odE卷,华为od机试真题E卷,华为OD,华为OD机试,华为OD机试真题,华为od机考,华为od机试D卷,华为od机试真题D卷,华为od手撕代码,华为od,华为od机试C卷,华为od e卷,华为2024e卷,od机试,2024E卷,华为OD机试E卷,什么是华为od,华为od介绍,全面了解华为od,2024华为od,如何备

KJ.JK 5万+

Android SDK开发实战:从架构设计到AAR/JAR打包发布全流程解析

在软件工程领域,模块化与代码复用是提升开发效率的核心实践。通过将通用功能封装为独立的软件包,开发者能够实现逻辑解耦与团队协作优化。其技术原理在于定义清晰的接口契约与依赖管理机制,确保组件的稳定性和兼容性。这种模式的技术价值在于降低系统耦合度、加速产品迭代,并促进技术资产沉淀。在移动开发场景中,Android SDK作为典型实现,广泛应用于支付、推送、统计等基础服务封装。本文聚焦Android SDK的工程化实践,深入探讨aar与jar打包的完整流程,涵盖模块化设计、依赖隔离策略、资源冲突规避等关键环节,并针

weixin_30614109的博客 390

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

android 的android httpClient详解

AndroidHttpClient结构: public final class AndroidHttpClient extends Object implements HttpClient 前言: 这类其实是Google对阿帕奇的HttpClient的一个封装,一些默认属性有android做了一些优化。 然后阿帕奇的HttpClient是对java...

weixin_33691700的博客 567

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

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

Android HTTP访问的两种方式(HttpClient和HttpURLConnection)

Android HTTP访问的两种方式(HttpClient和HttpURLConnection)

Crazy程序猿 5405

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Android入门:HttpClient介绍

一、HttpClient介绍 HttpClient是用来模拟HTTP请求的,其实实质就是把HTTP请求模拟后发给Web服务器; Android已经集成了HttpClient,因此可以直接使用; 注:此处HttpClient代码不只可以适用于Android,也可适用于一般的Java程序; HTTP GET核心代码: (1)DefaultHttpClient client = new Def

SinFeeLoo 671

android 5.1 httpclient,【Android进阶学习】Http编程之HttpClient

在Android开发中,Android SDK附带了Apache的HttpClient,它是一个完善的客户端。它提供了对HTTP协议的全面支持,可以使用HttpClient的对象来执行HTTP GET和HTTP POST调用。HTTP工作原理:1.客户端(一般是指浏览器,这里是指自己写的程序)与服务器建立连接2.建立连接后,客户端向服务器发送请求3.服务器接收到请求后,向客户端发送响应信息4.客户...

weixin_42363303的博客 573

Android HTTP 请求方式 HttpClient

环境准备 Java 开发时,后台的 Http 请求操作通常使用的是 org.apache.http.client.HttpClient,Android 开发同样可以使用这些第三方 API。 单纯就使用 Apache 的 HttpCLient 来说,Android 编码 与 Java 编码中 API 使用都是基本一样。 HttpClient 依赖 本人使用的是 Android Studio...

蚩尤后裔-汪茂雄 3340

Android之HttpClient

使用HttpClient发送请求,接收响应很简单,只要如下几步就行 第一步:创建HttpClient对象 第二步:如果发送GET请求,创建HttpGet对象;如果发送POST请求,创建HttpPost对象 第三步:发送请求是如果需要传递参数,可以调用setParams(HttpParams params)方法添加请求参数 (HttpGet和HttpPost都有这个方法),HttpPost也

人生就像旅程 1142

Android Http请求网络HttpClient和HttpUrlConnection

在Android API Level 9(Android 2.2)之前只能使用DefaultHttpClient类发送http请求。DefaultHttpClient是Apache用于发送http请求的客户端,其提供了强大的API支持,而且基本没有什么bug,但是由于其太过复杂,Android团队在保持向后兼容的情况下,很难对DefaultHttpClient进行增强。为此,Android团队从Android API Level 9开始自己实现了一个发送http请求的客户端类——–HttpURLConnec

蜗牛的小梦想 1202

HttpClient 教程 (一)

前言 超文本传输协议(HTTP)也许是当今互联网上使用的最重要的协议了。Web服务,有网络功能的设备和网络计算的发展,都持续扩展了HTTP协议的角色,超越了用户使用的Web浏览器范畴,同时,也增加了需要HTTP协议支持的应用程序的数量。 尽管java.net包提供了基本通过HTTP访问资源的功能,但它没有提供全面的灵活性和其它很多应用程序需要的功能。HttpClient就是寻求弥补这项空白...

weixin_34250709的博客 611

Android HTTP请求方式:HttpClient

获得Cookie:cookie = loginResponse.getFirstHeader(“Set-Cookie”).getValue();其实关于HttpClient的例子有很多,比如笔者曾经用它来抓学校教务系统上学生的课程表: 这就涉及到Cookie,模拟登陆的东西,说到抓数据(爬虫),一般我们是搭配着JSoup来解析 抓到数据的,有兴趣可以自己查阅相关资料,这里贴下笔者毕设app里获取网页部分的关键 代码!// 先发送get请求 获取cookie值和__ViewState值。

D0126_的博客 812

Android:使用HttpClient接口实现网络通信

在Android中,我们可以通过使用标准的Java接口来完成Android应用程序的联网操作。但是在实际开发中,可能会需要用到更复杂的联网操作,为此,Android平台提供了Apache HttpClient接口,为客户端的HTTP编程提供了高效、便捷、功能丰富的工具包支持。   Android平台在引入Apache HttpClient的同时,还对其进行了一些封装和扩展,如设置缺省的HTTP超

chaituan的专栏 820

Android HttpClient及连接管理器

超文本传输协议HTTP也许是当今互联网上使用的最重要的协议了。Web服务有网络功能的 设备和网络计算的发展都持续扩展了HTTP协议的角色超越了用户使用的Web浏览器范畴 同时也增加了需要HTTP协议支持的应用程序的数量。  尽管java.net包提供了基本通过HTTP访问资源的功能但它没有提供全面的灵活性和其它很多应 用程序需要的功能。HttpClient就是寻求弥补这项空

Hknock的专栏 8382
上一篇: android单元测试初探
下一篇: 计算机网路的粗浅理解
class_brick
博客等级 码龄12年 223粉丝 76原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值