Apache HttpComponents 如何在正常结束前中止一个HTTP请求
2023-09-11 14:16:57 时间
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(); } } }
相关文章
- phoenix连接hbase数据库,创建二级索引报错:Error: org.apache.phoenix.exception.PhoenixIOException: Failed after attempts=36, exceptions: Tue Mar 06 10:32:02 CST 2018, null, java.net.SocketTimeoutException: callTimeou
- 接收对 http://192.168.1.18:8001/ObtainData/Service 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。
- Apache Maven ToolChains的使用
- Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'company' in 'class java.lang.String'
- 压力测试工具ab - Apache HTTP server benchmarking tool
- Apache Kylin权威指南3.3 触发增量构建
- apache配置http basic auth
- Apache-Flink深度解析-DataStream-Connectors之Kafka
- Apache用户目录枚举工具apache-users
- 漏洞复现----12、Apache Flink目录穿越漏洞(CVE-2020-17519 )
- HTTP Post Request using Apache Commons
- 《PHP、MySQL和Apache入门经典(第5版)》一一2.7 基本安全规则
- Windows系统在本地配置一个apache域名的方法
- Apache Curator与Zookeeper版本兼容性异常:org.apache.zookeeper.KeeperException$UnimplementedException: KeeperErrorCode =Unimplemented
- Linux+Mysql+Apache+Php测试环境部署
- HTTP/2 服务器推送(Server Push)教程(HTTP/2 协议的主要目的是提高网页性能,配置Nginx和Apache)
- 本地Apache配置虚拟主机/域名
- apache jserv漏洞Apache漏洞
- 【Spring Cloud】如何把Feign默认的HTTP客户端URLConnection更换成支持连接池的Apache HttpClient或OKHttp
- apache http跳转到https代码
- Apache配置文件httpd.conf/htaccess中deny和allow的使用
- Apache 禁用IP 访问 和 HTTP 跳转 HTTPS
- 试用Apache/Nginx反向代理多个Web应用
- HTTP(http+抓包Fiddler+协议格式+请求+响应)
- apache开源项目--Apache POI