package org.apache.http.examples.client;

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();
try {
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();
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
} }

Apache HttpComponents 如何在正常结束前中止一个HTTP请求的更多相关文章

  1. Apache HttpComponents Client 4.0快速入门/升级-2.POST方法访问网页

    Apache HttpComponents Client 4.0已经发布多时,httpclient项目从commons子项目挪到了HttpComponents子项目下,httpclient3.1和 h ...

  2. org.apache.httpcomponents httpclient 发起HTTP JSON请求

    1. pom.xml <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactI ...

  3. JAVA中使用Apache HttpComponents Client的进行GET/POST请求使用案例

    一.简述需求 平时我们需要在JAVA中进行GET.POST.PUT.DELETE等请求时,使用第三方jar包会比较简单.常用的工具包有: 1.https://github.com/kevinsawic ...

  4. Apache HttpComponents中的cookie匹配策略

    Apache HttpComponents中的cookie匹配策略 */--> pre.src {background-color: #292b2e; color: #b2b2b2;} pre. ...

  5. httpclient工具使用(org.apache.httpcomponents.httpclient)

    httpclient工具使用(org.apache.httpcomponents.httpclient) 引入依赖 <dependency> <groupId>org.apac ...

  6. commons-httpclient和org.apache.httpcomponents的区别

    <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpc ...

  7. Apache HttpComponents 工具类 [ HttpUtil ]

    pom.xml <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId&g ...

  8. org.apache.httpcomponents.httpclient

    apache org doc :http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e49 ...

  9. 接收对 http://192.168.1.18:8001/ObtainData/Service 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。

    [2015/8/5 19:28:49]错误信息:接收对 http://192.168.1.18:8001/ObtainData/Service 的 HTTP 响应时发生错误.这可能是由于服务终结点绑定 ...

随机推荐

  1. HDUOJ---1241Oil Deposits(dfs)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  2. 在TFS 2013上,使用tf workspace命令删除其他用户的工作区

    8月25日补充:如果想批量删除工作区,你可以使用第三方工具MSBuild Sidekick http://www.attrice.info/downloads;或者自己编写一个bat脚本,但是缺陷是需 ...

  3. 目的可疑,但方法非常值得学习的书——leo鉴书56

    书中提到写作手法绝对值得学习,为此能够打四颗星.   作者是个买直销产品的.靠写字让别人买自己的东西.当中特别强调了卖的多是太空时代的产品,意思就是读者非常可能并不须要,多半是被眼花缭乱的广告词儿骗了 ...

  4. 关于apache服务器加载so的报错

    早上突然发现我的虚拟机上的WEB应用访问不了了,后台检查httpd服务,无法启动,出现一行提示: ①starting httpd: httpd: Syntax error on line 163 of ...

  5. -174dBm的含义

    常温下(290K)一个热电阻会产生少量的噪声能量P=kTB k = 玻尔兹曼常数(1.38 x 10–23 J/K)T = 温度(K)B = 噪声带宽(Hz) 由于总噪声功率是测量带宽的函数,数值通常 ...

  6. ActiveMQ + NodeJS + Stomp 入门

    NodeJS + stomp-client 入门 准备 下载ActiveMQ并安装 执行bin\win32\activemq.bat启动MQ服务 打开http://localhost:8161/adm ...

  7. spring中action和url的对应关系

    spring 中, action和url的对应关系             在web.xml中,这样配置:           <servlet-mapping >             ...

  8. C#用ado.net访问EXCEL的常见问题及解决方法

    C#用ado.net访问EXCEL的常见问题及解决方法,除了像sql server,access常见的数据库,其实Excel文件也可以做为数据库访问. ado.net访问excel的实例: OleDb ...

  9. 使用B::Deparse模块对perl代码反汇编

    Perl用很多默认操作和习惯用法,如果对某些代码不确定,perl编译器的真实理解方式,可以用Deparse模块反汇编看一下. 比如下面代码: while(<STDIN>){ print & ...

  10. cocos2d-x--精灵反转效果--CCOrbitCamera

    CCSprite* pSprite = CCSprite::spriteWithFile("grossini.png"); pSprite->setPosition(ccp( ...