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

HttpClient异常总结

    博客分类:
  • http
阅读更多

Exception handling

(排在前面的异常的优先级低)

http://hc.apache.org/httpclient-3.x/exception-handling.html

There are two main type of exceptions that the user of HttpClient may encounter when executing HTTP methods:

 

1.transport exceptions

 

java.io.IOException

java的IOException代表HttpClient的通用的transport exceptions

 

org.apache.commons.httpclient.NoHttpResponseException

  • In some circumstances, usually when under heavy load, the web server may be able to receive requests but unable to process them. A lack of sufficient resources like worker threads is a good example. This may cause the server to drop the connection to the client without giving any response. HttpClient throws NoHttpResponseException when it encounters such a condition. In most cases it is safe to retry a method that failed with NoHttpResponseException.
  • 在某些情况下,通常在高负载时,web server可以接收到请求,但无法处理它们。缺乏足够的资源,如缺少工作线程。这可能会导致服务器将连接丢回到客户端,而不给予任何回应。HttpClient抛出nohttpresponseexception遇到这种情况的时候。在大多数情况下,一个方法抛出NoHttpResponseException,重试是一个安全的办法。

 

org.apache.commons.httpclient.ConnectTimeoutException

  • This exception signals that HttpClient is unable to establish a connection with the target server or proxy server within the given period of time.
  • HttpClient无法在指定的时间内与目标服务器或代理服务器建立连接。

 

org.apache.commons.httpclient.ConnectionPoolTimeoutException

  • This exception can only occur when using the multithreaded connection manager. The exception signals that the connection manager fails to obtain a free connection from the connection pool within the given period of time.
  • ConnectionPoolTimeoutException只会发生在使用多线程connection manager的时候。connection manager无法在一定时间内获连接池中空闲的连接,就会抛出这个异常。

 

2.protocol exceptions

 

org.apache.commons.httpclient.HttpException

  • HttpException represents an abstract logical error in HttpClient. Generally this kind of exception cannot be automatically recovered from.
  • HttpClient中用HttpException代表抽象的逻辑错误,通常这种异常不能自动恢复。

 

org.apache.commons.httpclient.ProtocolException

  • ProtocolException signals a violation of the HTTP specification. It is important to note that HTTP proxies and HTTP servers can have different level of HTTP specification compliance. It may be possible to recover from some HTTP protocol exceptions by configuring HttpClient to be more lenient about non-fatal protocol violations.
  • ProtocolException 表示违反HTTP规范。

 

中间还有一些HttpClient的内部异常

 

org.apache.commons.httpclient.RedirectException

  • RedirectException signals violation of the HTTP specification caused by an invalid redirect response. If the application that uses HttpClient needs to be more lenient about redirect responses, it may choose to disable automatic redirect processing and implement a custom redirect strategy.
  • 无效的重定向相应。可以选择禁用自动重定向处理,并实现自定义的重定向策略。

 

org.apache.commons.httpclient.URIException

  • URIException is thrown when the request URI violates the URI specification.
  • 请求uri不符合规范会抛出URIException。

 

分享到:
评论

相关推荐

    HttpClient学习总结.docx

    1. 创建HttpClient实例,可以设置恢复策略以处理异常情况。 2. 创建GetMethod实例,传入请求的URL。 3. 调用HttpClient的executeMethod方法执行GetMethod,同时捕获可能出现的HttpException和IOException。 4. 检查...

    httpclient4.3工具类

    9. **异常处理**:`httpclientUtils`可能会包含对HttpClient抛出的各种异常的处理逻辑,如`IOException`、`HttpException`等,以提供更友好的错误信息和处理方案。 10. **线程安全**:为了适应多线程环境,`...

    HTTPClient 的一个封装

    文件名为httpClient的压缩包很可能包含了封装HttpClient的相关代码,可能包括配置类、请求执行类、异常处理类等。解压并研究这些文件,可以帮助我们理解具体是如何进行封装的,也可以为我们的项目提供参考和学习的...

    HttpClient实现文件下载

    #### 六、总结 通过上述分析,我们可以看到使用 HttpClient 实现文件下载的过程相对简单,主要涉及到了 HTTP 请求的构造、执行以及响应数据的处理等步骤。此外,还需要注意异常处理及资源的释放,以确保程序的健壮...

    httpclient4.5源码学习

    总结,HttpClient 4.5 是一款强大且灵活的 HTTP 客户端库,其源码结构清晰,设计模式巧妙,通过深入学习和实践,开发者可以更好地利用它来实现高效、安全的网络通信。理解 HttpClient 4.5 的源码,不仅有助于我们...

    httpclient3.1 javadoc chm版

    总结,HttpClient 3.1 JavaDoc CHM版为开发者提供了全面的API文档,帮助他们理解和使用HttpClient进行HTTP通信。虽然HttpClient已经更新到更高级的版本,但这个旧版本的文档对于维护旧项目或理解HTTP通信基础仍然...

    httpclient4.3中文教程

    如果请求执行失败,HttpClient 会抛出异常。此外,HttpClient 还支持设置请求头、身份验证、连接管理、超时控制等高级功能,以满足各种复杂的网络通信需求。 HttpClient 不是浏览器,它不会解析 HTML 内容或执行 ...

    Java-HttpClient帮助文档

    总结,HttpClient是Java中强大的HTTP客户端工具,提供了丰富的功能和高度的灵活性,适用于各种网络编程场景。通过理解和掌握HttpClient的使用,开发者能够更好地实现与HTTP服务器的交互,处理复杂的网络任务。查阅...

    httpclient官网教程中文版

    ### Httpclient官网教程中文版知识点总结 #### 一、引言 HTTP协议作为互联网的核心通信标准之一,在现代网络服务及物联网设备中扮演着至关重要的角色。随着技术的发展,越来越多的应用和服务依赖于HTTP协议来实现...

    最全最新httpclient4.3.3

    总结,Apache HttpClient 4.3.3是Java开发者进行HTTP通信的强大工具。通过深入理解和应用,我们可以构建高效、可靠的网络应用程序,并在抓包、API调用等场景中游刃有余。了解和掌握HttpClient,无疑是提升Java网络...

    apache httpclient 源码和 jar包

    4. **错误处理**:通过源码,我们可以看到HttpClient如何处理网络异常、超时等问题,这对于我们在实际开发中遇到类似问题时提供解决方案有很大的帮助。 jar包部分: 1. **使用方式**:HttpClient的jar包包含了所有...

    httpclient-4.3.jar

    5. 精细化的错误处理:HttpClient 4.3提供了丰富的异常类型,方便开发者处理各种可能出现的问题。 三、使用方法 1. 创建HttpClient实例:通过HttpClientBuilder,用户可以定制化构建HttpClient对象,设置连接超时...

    httpclient 4.3 中文版

    如果请求执行失败,HttpClient 会抛出异常。 **示例代码**: ```java CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpget = new HttpGet("http://localhost/"); ...

    httpclient-4.5.6.rar

    总结,HttpClient 4.5.6 是一个强大且灵活的 HTTP 客户端库,其丰富的功能和优秀的性能使其在 Java 开发领域备受青睐。通过理解和掌握其使用方法和最佳实践,开发者可以更好地利用网络资源,实现高效、安全的通信。

    httpclient4.3.5

    总结,HttpClient 4.3.5作为官方网站提供的最新版本,不仅增强了功能,还优化了性能。通过了解其核心特性,结合实际案例,开发者可以更高效地利用HttpClient进行网络通信,提升应用的网络性能。在实际开发中,根据...

    如何在WPF应用程序中通过HttpClient调用Web API

    总结来说,WPF中的异步调用Web API通过HttpClient能确保应用程序的响应性和用户体验。通过正确配置和使用HttpClient,开发者可以高效地与Web API进行通信,处理数据请求和响应,同时避免主线程被阻塞。记住,良好的...

    httpclient-4.5.jar

    此外,正确处理异常和错误,以及适时关闭资源,也是使用HttpClient时的关键。 总结,`httpclient-4.5.jar`及其相关依赖提供了全面的HTTP客户端功能,适用于各种Java应用程序,无论是简单的HTTP请求,还是复杂的HTTP...

    httpclient 3.1 jar包 手册 源代码

    总结,HttpClient 3.1是Java网络编程的一个强大工具,提供了丰富的功能和高度的可定制性。通过深入理解其源代码和使用手册,开发者可以有效地利用HttpClient来构建高质量的HTTP客户端应用程序。

    HttpClient 4文件上传

    ### HttpClient 4 文件上传知识点详解 ...关键在于正确构建`MultipartEntity`对象,以及处理好请求和响应过程中可能出现的各种异常情况。同时,需要注意解决中文乱码等问题,以确保数据传输的准确性。

    httpclient 4.0.3 源代码

    总结来说,HttpClient 4.0.3源代码的解析有助于我们理解其背后的逻辑和设计模式,从而更有效地利用这个库进行HTTP通信。无论是请求构建、连接管理,还是安全性、重试策略,HttpClient都提供了高度定制化的选项,使其...

Global site tag (gtag.js) - Google Analytics