`
Jatula
  • 浏览: 276724 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

HttpClient Examples:Abort method

阅读更多

官方主頁:http://hc.apache.org/

 

Components

Abort method

This example demonstrates how to abort an HTTP request before its normal completion.

 

中止方法

这个实例示范怎样中止一个HTTP请求在正常完成前。

 

package cn.lake.util;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

/**
 * This example demonstrates how to abort an HTTP method before its normal completion.
 */
public class ClientAbortMethod {

	public final static void main(String[] args) throws Exception {
		HttpClient httpclient = new DefaultHttpClient();

		HttpGet httpget = new HttpGet("http://www.apache.org/");

		System.out.println("executing request " + httpget.getURI());
		HttpResponse response = httpclient.execute(httpget);
		HttpEntity entity = response.getEntity();

		System.out.println("----------------------------------------");
		System.out.println(response.getStatusLine());
		if (entity != null) {
			System.out.println("Response content length: " + entity.getContentLength());
		}
		System.out.println("----------------------------------------");

		// Do not feel like reading the response body
		// Call abort on the request object
		httpget.abort();
	}

}

 

httpget.abort();这句就是中止操作!

 

输出结果

 

executing request http://www.apache.org/
log4j:WARN No appenders could be found for logger (org.apache.http.impl.client.ClientParamsStack).
log4j:WARN Please initialize the log4j system properly.
----------------------------------------
HTTP/1.1 200 OK
Response content length: 21680
----------------------------------------

 

翻譯的不好,請見諒!

分享到:
评论

相关推荐

    commons-httpclient-3.1jar包

    《Apache Commons HttpClient 3.1详解》 Apache Commons HttpClient 是一个功能强大的Java库,专为实现客户端HTTP通信而设计。这个3.1版本是HttpClient的一个重要里程碑,它提供了丰富的功能和改进,使得开发者能够...

    HttpClient问题:The server failed to respond with a valid HTTP resp

    此外,`get.abort()`用于取消请求,确保在异常情况下释放连接,但应该在所有资源都被妥善处理后才执行。 5. **多线程和连接管理**:如果在多线程环境中使用HttpClient,可能需要特别注意连接管理和线程安全。使用`...

    httpclient-4.5.12-API文档-中文版.zip

    Maven坐标:org.apache.httpcomponents:httpclient:4.5.12; 标签:apache、httpcomponents、httpclient、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档...

    httpclient-4.5.13-API文档-中文版.zip

    Maven坐标:org.apache.httpcomponents:httpclient:4.5.13; 标签:apache、httpcomponents、httpclient、jar包、java、中文文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档...

    httpclient-4.5.13-API文档-中英对照版.zip

    Maven坐标:org.apache.httpcomponents:httpclient:4.5.13; 标签:apache、httpcomponents、httpclient、jar包、java、中英对照文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览...

    可用org.apache.commons.httpclient-3.1.0.jar.zip

    import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods....

    commons-httpclient3.1.jar,commons-codec1.3.jar,commons-logging1.1.1.jar

    标题中的"commons-httpclient3.1.jar,commons-codec1.3.jar,commons-logging1.1.1.jar"指的是三个关键的Java库文件,它们是Apache HttpClient项目的一部分,用于在Java应用程序中实现HTTP通信。这些JAR(Java ...

    httpclient-4.5jar

    httpclient-4.5所需jar包,里面包含httpclient-4.5.jar等等10个必须的开发包。 1.commons-codec-1.9.jar 2.commons-logging-1.2.jar 3.fluent-hc-4.5.jar 4.httpclient-4.5.jar 5.httpclient-cache-4.5.jar 6....

    Software caused connection abort: recv failed

    标题:“Software caused connection abort: recv failed” 描述:“Software caused connection abort: recv failed” 知识点解析: ### 背景介绍 “Software caused connection abort: recv failed”这一错误...

    httpclient

    HttpClient 4.2.5是HttpClient的一个稳定版本,它引入了许多改进和修复,提高了性能和稳定性。同时,HttpClient依赖于HttpCore库,这是Apache提供的基础HTTP协议处理组件,httpcore-4.4.1.jar即为该组件的4.4.1版本...

    httpclient-4.5jar包

    《HttpClient 4.5详解与应用实践》 HttpClient是一个开源的Java库,由Apache软件基金会维护,主要用于在HTTP协议上实现客户端的通信。版本4.5是HttpClient的一个稳定版本,提供了许多增强的功能和优化,使其成为...

    httpclient-4.5.5-API文档-中文版.zip

    赠送jar包:httpclient-4.5.5.jar; 赠送原API文档:httpclient-4.5.5-javadoc.jar; 赠送源代码:httpclient-4.5.5-sources.jar; 包含翻译后的API文档:httpclient-4.5.5-javadoc-API文档-中文(简体)版.zip ...

    HttpClientUtil:一个Http请求使用HttpClient访问服务器,我们也可以上传文件到服务器,比如文件或图片。它提供接口来更新你的上传进度

    - 创建 HttpClient 实例:首先,我们需要创建一个 HttpClient 实例,这可以通过 HttpClientBuilder 或直接使用 HttpClients.createDefault() 方法完成。 - 创建请求:然后,我们需要构造一个 HttpRequestBase 对象...

    httpClient实例httpClient调用 http/https实例 忽略SSL验证

    这个实例主要涉及如何配置HttpClient来忽略SSL(Secure Socket Layer)验证,这对于在开发和测试环境中处理自签名证书或未认证的服务器非常有用。以下将详细介绍HttpClient的使用以及如何进行SSL验证的忽略。 首先...

    ribbon-httpclient-2.2.5.jar

    ribbon-httpclient-2.2.5.jar

    commons-httpclient-3.0.jar JAVA中使用HttpClient可以用到

    《JAVA中使用HttpClient:commons-httpclient-3.0.jar详解》 在JAVA开发中,进行HTTP请求时,Apache的HttpClient库是一个不可或缺的工具。本文将深入解析`commons-httpclient-3.0.jar`,它是HttpClient的一个重要...

    org.apache.commons.httpclient-3.1.jar

    4. **易于使用**:提供了一系列简单易用的接口,如HttpMethod接口,允许开发者直接发送GET、POST等HTTP方法。 5. **代理支持**:HttpClient可以处理代理服务器的配置,包括基本认证和NTLM认证。 6. **身份验证**:...

    wechatpay-apache-httpclient:微信支付 APIv3 Apache HttpClient装饰器(decorator)

    wechatpay-apache-httpclient 概览 的扩展,实现了请求签名的生成和应答签名的验证。...implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.2.2' Maven 加入以下依赖 <groupId>com.github.w

    httpclient-4.5.jar

    在这个版本中,我们关注的是`httpclient-4.5.jar`,这是一个包含了HttpClient 4.5核心功能的Java库。这个库的发布日期为2016年7月19日,它提供了许多改进和新特性,旨在帮助开发者更高效、更稳定地构建网络应用程序...

    httpclient4.2.2.zip

    HttpClient 4.2.2是HttpClient系列的一个重要版本,它在4.2.x系列中具有稳定性和性能的双重保障。 一、HttpClient 4.2.2的基础概念与特性 1. 基于Java的HTTP客户端接口:HttpClient 4.2.2提供了一套全面的API,使得...

Global site tag (gtag.js) - Google Analytics