`
macken
  • 浏览: 349827 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

URLConnection与HttpClient的对比

    博客分类:
  • Java
 
阅读更多
from:http://www.innovation.ch/java/HTTPClient/urlcon_vs_httpclient.html
URLConnectionHTTPClient
MethodsOnly HEAD, GET, POST, PUT, DELETE, TRACE and OPTIONS.Has HEAD, GET, POST, PUT, DELETE, TRACE and OPTIONS, plus any arbitrary method, such as those from WEBDav and IPP.
Response CodesThe response code, headers, and body can only be read if the response code was less than 400 - for any 4xx or 5xx response code, you only get IOException's when trying to get any response info.The response code, all headers, and the body can always be read normally.
Proxies and SOCKSFull support (SOCKS: Version 4 only)Full support (SOCKS: both version 4 and 5)
AuthorizationSupport for Basic and an early version of Digest in JDK 1.2 or later, only. The current version of Digest authentication (which is the one supported by most servers) is not supported, and due to a bug of theirs they won't even recognize the digest info returned by Apache.Support for Basic and Digest Authentication; other schemes can be added.
CookiesNoYes
True request output streamsNo - all data is fully buffered before it is sent.Yes - HttpOutputStream will stream directly to the socket.
True response input streamsUnder JDK 1.2, yes; under JDK 1.3 only if the response is not sent using the chunked encoding (this excludes most server-push responses).Yes.
Persistent ConnectionsHTTP/1.0 Keep-Alive's in JDK 1.1 and JDK 1.2; JDK 1.3 has HTTP/1.1 persistence.Supports HTTP/1.0 Keep-Alive's and HTTP/1.1 persistence.
Pipelining of RequestsNo.Yes.
Can set TimeoutsNo.Yes.
Can handle protocols other than HTTPYes (e.g. ftp, gopher, mailto, and file are provided)No.
Can do HTTP over SSL (https)Appropriate SSL package (such as JSSE) which provides an appropriate client must be installed.Patches are available for various free and commercial SSL packages
Source code availableNo.Yes.
分享到:
评论
1 楼 kingdelee 2013-06-21  
HTTPClient完胜?

相关推荐

    HttpURLConnection和HTTPClient的比较,以及使用规则

    NULL 博文链接:https://xiaowei-qi-epro-com-cn.iteye.com/blog/1973295

    java.net.URLConnection发送HTTP请求与通过Apache HttpClient发送HTTP请求比较

    有两种常见的方法:一是使用`java.net.URLConnection`类,二是通过Apache HttpClient库。这篇文章将对比这两种方法,探讨它们的优缺点以及适用场景。 `java.net.URLConnection`是Java标准库中的一个类,可以直接...

    Web Service Tester

    通过这个"Web Service Tester"项目,开发者可以学习到如何在Android环境中实现网络请求,对比URLConnection和HttpClient的使用差异,从而在实际项目中选择最适合的方法。同时,这也是一个很好的实战练习,加深对...

    Android例子源码使用HttpClient获取网页html源代码

    本例子源码展示了如何利用Apache HttpClient库来实现这一功能,同时也对比了另一种常见的网络访问方式——URLConnection。以下是对这两个方法的详细解释。 首先,我们来看`HttpClient`的使用。Apache HttpClient是...

    Android 中HttpURLConnection与HttpClient使用的简单实例

    对比两者,HttpURLConnection更轻量级,更节能,且在Android 6.0以后被官方推荐使用。然而,HttpClient提供了更丰富的功能,如重试策略、连接池等,对于复杂场景可能更为适用。在Android 5.0之前,由于...

    Android调用Web应用浅析.pdf

    与HttpClient类似,它也支持GET和POST请求,但使用的是不同的API。 对于数据交换格式,文章对比了XML和JSON的解析。XML是一种结构化数据表示,适用于复杂的数据结构,而JSON则以其简洁和易用性而流行,常用于轻量级...

    自己动手写网络爬虫

    - **核心类库**:掌握Java中的网络编程类库如URLConnection、HttpClient等,以及DOM解析器和XPath表达式等用于网页内容的解析。 #### 三、网络爬虫设计与实现 ##### 3.1 架构设计 一个高效的网络爬虫系统应该具备...

    java学习笔记,全程

    - HttpURLConnection与HttpClient:对比两者在网络请求中的应用和优缺点。 3. **集合类** - ArrayList、LinkedList、HashSet、HashMap:研究这些常用集合类的实现原理,掌握它们的添加、删除、查找操作,以及适用...

    HttpURLConnection 的使用二

    在提供的博客链接中,作者可能会分享关于如何有效使用`HttpURLConnection`进行HTTP请求的实践案例,包括错误处理、性能优化以及与其他库(如Apache HttpClient)的对比分析。通过阅读和学习这样的内容,开发者可以更...

Global site tag (gtag.js) - Google Analytics