- 浏览: 449232 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (267)
- java (8)
- 求职&面试 (1)
- linux (33)
- windows (1)
- C++ (5)
- android (12)
- QT (1)
- 经验 (1)
- memory-leaks (1)
- Streaming&V/A (1)
- network&security (5)
- SCM (13)
- mysql (10)
- browsers (4)
- Windows APIs (2)
- opensource (1)
- pm (1)
- GDI (1)
- database (14)
- MFC (1)
- web&fronts (17)
- Tomcat (4)
- OLE (1)
- 观后感 (1)
- Production (2)
- UML (3)
- Javascript (7)
- Cloud Computing&SAAS (5)
- SoftwareEngineering (1)
- Computer&Maintenance (1)
- Web (8)
- Desgin (1)
- J2ee (10)
- mysql cluster (0)
- LB&HA (2)
- webserver (11)
- php (5)
- cas&authtication (0)
- Languages (1)
- IDEs (3)
- architecture (2)
- iOS (8)
- spring (3)
- webservices (1)
- security (1)
- MVCFrameworks (2)
- bservices (0)
- build-tools (2)
- unittest (1)
- spring-security (0)
- sphinx (2)
- hibernate (1)
- mybatis (2)
- search (0)
- nginx (2)
- design&production (2)
- DFS (0)
- algorithm (0)
- distributed&network (0)
- blogs (0)
- os&admin (0)
- fastcgi (0)
- kv-db (0)
- operation&maintenance (1)
- productions (9)
- 养生 (1)
- appserver (1)
- HTTP (2)
- test (1)
- erlang (2)
- browser (0)
- 非技术 (2)
- mobiles (2)
- cloud computing (2)
- Business (2)
- maven (1)
- python (5)
- 人生 (0)
- Cryptography (3)
- CV (0)
- cms (2)
- jqm (2)
- html (2)
- flex (1)
- redmine (1)
- iptables (1)
- groovy (1)
- scala (1)
- grails (1)
- ftp (3)
- vsftpd (2)
- lua (0)
- chroot (3)
- jailkit (3)
- UED (0)
- myeclipse (2)
- ide (2)
- eclipse (2)
最新评论
-
Nick712:
http://blog.csdn.net/victory08/ ...
处理SVN出现:Cleanup failed to process the following paths: xxx -
xs6262460:
Spring AOP根据JdbcTemplate方法名动态设置数据源 -
xhpscdx:
我的解决办法是把D:\ACRS\Projects\TAIS 下 ...
处理SVN出现:Cleanup failed to process the following paths: xxx -
hnraysir:
总结得相当不错,支持下。
使用CodeIgniter 创建 RESTful 服务 REST API【原创译文】 -
云上太阳:
这个必须评论下,间接的救过俺的命啊
解决tomcat启动报错,加强错误日志的显示:
HttpClient压缩传输的代码,大部分都不靠谱,apache httpclient 官网的最靠谱,亲测!
------------------------------------------------------------------------------------------------------
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.examples.client;
import java.io.IOException;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.client.entity.GzipDecompressingEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
/**
* Demonstration of the use of protocol interceptors to transparently
* modify properties of HTTP messages sent / received by the HTTP client.
* <p/>
* In this particular case HTTP client is made capable of transparent content
* GZIP compression by adding two protocol interceptors: a request interceptor
* that adds 'Accept-Encoding: gzip' header to all outgoing requests and
* a response interceptor that automatically expands compressed response
* entities by wrapping them with a uncompressing decorator class. The use of
* protocol interceptors makes content compression completely transparent to
* the consumer of the {@link org.apache.http.client.HttpClient HttpClient}
* interface.
*/
public class ClientGZipContentCompression {
public final static void main(String[] args) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
public void process(
final HttpRequest request,
final HttpContext context) throws HttpException, IOException {
if (!request.containsHeader("Accept-Encoding")) {
request.addHeader("Accept-Encoding", "gzip");
}
}
});
httpclient.addResponseInterceptor(new HttpResponseInterceptor() {
public void process(
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
HttpEntity entity = response.getEntity();
if (entity != null) {
Header ceheader = entity.getContentEncoding();
if (ceheader != null) {
HeaderElement[] codecs = ceheader.getElements();
for (int i = 0; i < codecs.length; i++) {
if (codecs[i].getName().equalsIgnoreCase("gzip")) {
response.setEntity(
new GzipDecompressingEntity(response.getEntity()));
return;
}
}
}
}
}
});
HttpGet httpget = new HttpGet("http://cppmule.zapto.org/acr/acrphone-service/area/cities");
// Execute HTTP request
System.out.println("executing request " + httpget.getURI());
HttpResponse response = httpclient.execute(httpget);
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
System.out.println(response.getLastHeader("Content-Encoding"));
System.out.println(response.getLastHeader("Content-Length"));
System.out.println("----------------------------------------");
HttpEntity entity = response.getEntity();
if (entity != null) {
String content = EntityUtils.toString(entity);
System.out.println(content);
System.out.println("----------------------------------------");
System.out.println("Uncompressed size: "+content.length());
}
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
}
发表评论
-
推荐10个Java开源CMS系统
2013-02-16 17:39 0推荐10个Java开源CMS系统 ... -
JavaMelody系统监控工具使用配置
2013-02-02 01:09 1341JavaMelody系统监控工具使用配置 2 ... -
Sun jdk、Openjdk、Icedtea jdk关系
2012-12-28 16:02 1115Sun jdk、Openjdk、Icedtea jdk ... -
android中实现消息推送
2012-12-05 23:30 0android中实现消息推 ... -
androidpn的学习研究(五)【转】androidpn-client 常见BUG解决方法
2012-12-05 22:57 0androidpn的学习研究(五)【转】andro ... -
解决androidpn服务器端掉线不会重连的问题
2012-12-05 22:50 6025解决androidpn服务器端掉线不会重连的问题 wi ... -
jetty http client 实现分析
2012-11-25 00:15 0jetty http client 实现分析 ... -
HttpClient的超时用法小记
2012-11-25 00:02 0HttpClient的超时用法小记 Ht ... -
关于 java.util.concurrent.RejectedExecutionException
2012-11-05 16:15 0关于 java.util.concurrent.Reje ... -
异常设计----何使用异常的原则
2012-09-19 17:49 904异常设计----何使用异常的原则 摘要 本文 ... -
JAVA异常设计原则
2012-09-19 17:49 783JAVA异常设计原则 ... -
ssh(Struts+Spring+Hibernate)环境搭建,实现登录
2012-07-26 09:27 1123新建表test 表的属性为主 ... -
Java框架数据库连接池比较(c3p0,dbcp和proxool)
2012-06-12 21:42 1503现在常用的开源数据连接池主要有c3p0,dbcp和proxoo ...
相关推荐
- 使用压缩算法(如gzip)减小传输的数据量。 在实际应用中,开发者可以根据具体需求对HttpClient进行细致的配置和定制,使其更好地适应不同的网络环境和安全要求。HttpClient 4.2.5是一个强大而灵活的工具,对于...
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-Logging允许程序在不修改代码的情况下切换到其他日志框架,如Log4j或Java内置的日志系统。 了解这些库后,我们可以深入学习以下关键知识点: 1. **HttpClient的使用**:如何创建HttpClient实例,设置请求...
- 在Eclipse 中,你可以通过"File" -> "Import" -> "Existing Projects into Workspace" 导入Apache HttpClient 4.5 的源代码项目。 - 将下载的压缩包解压,然后在导入对话框中选择解压后的目录,确保"Copy ...
c++ HttpClient 最新代码c++ HttpClient 最新代码c++ HttpClient 最新代码c++ HttpClient 最新代码c++ HttpClient 最新代码c++ HttpClient 最新代码c++ HttpClient 最新代码c++ HttpClient 最新代码c++ HttpClient ...
Apache HttpClient 是一个强大的Java库,用于执行HTTP请求。在4.5.12版本中,它提供了丰富的功能,包括支持HTTP/1.1和部分HTTP/2协议,连接管理,重试策略,以及多种认证机制。这个源码版本是学习HTTP通信、网络编程...
7. **性能优化**:使用连接池提高性能,控制线程,处理大文件传输。 在实际开发中,HttpClient还可以与其他Apache Commons库,如IO和Lang,一起使用,以增强功能,例如处理输入/输出流,字符串操作等。 总的来说,...
- `LICENSE.txt`:包含了Apache Commons HttpClient的许可协议,它遵循Apache 2.0许可证,允许免费使用和修改源代码。 - `README.txt`:一般提供了项目的简介和快速入门指南。 - `NOTICE.txt`:通常列出库中可能包含...
标题中的"org.apache.commons.httpclient相关架包"指的是这个库的一系列组件,主要包含在`httpclient.jar`文件中。这个JAR文件包含了HttpClient库的所有必需类和资源,可以被导入到Java项目中以实现HTTP通信功能。 ...
apache httpclient document apache httpcore document
4. **错误处理**:通过源码,我们可以看到HttpClient如何处理网络异常、超时等问题,这对于我们在实际开发中遇到类似问题时提供解决方案有很大的帮助。 jar包部分: 1. **使用方式**:HttpClient的jar包包含了所有...
此外,Apache HttpClient库已经被弃用,现在推荐使用Java 7及更高版本内置的`java.net.HttpURLConnection`或更现代的库如Apache HttpClient 4.x或OkHttp。不过,对于理解HTTP客户端编程的基本原理,HttpClient仍然是...
它是Apache软件基金会的Jakarta项目的一部分,被广泛用于开发需要与Web服务器交互的应用程序。在本文中,我们将深入探讨HttpClient的核心概念、主要功能以及如何使用它来实现网络爬虫。 **HttpClient 主要特点** 1...
Apache Commons HttpClient是一个流行...无论你是构建Web服务客户端、爬虫,还是进行任何需要与Web服务器交互的应用,这个资源包都是不可或缺的。使用HttpClient,可以高效、灵活地实现HTTP通信,提升应用的网络功能。
wechatpay-apache-httpclient-0.2.1.jar
本实例将深入讲解如何使用HttpClient进行网络传输。 一、HttpClient基本概念 HttpClient是一个实现了HTTP/1.0和HTTP/1.1协议的客户端编程工具包。它不仅支持基本的HTTP方法,还支持HTTPS、Cookie管理、连接池、...
2. HttpClient不能做的事情 明确地讲,HttpClient并不是一个网络浏览器,它不会缓存内容,不会执行HTML中的JavaScript代码,也不会猜测内容类型或者对请求/重定向URI进行重新格式化。其功能仅限于发送和接收HTTP报文...
《HttpClient 4.0.3源代码解析》 HttpClient是一个由Apache基金会开发的开源HTTP客户端API,广泛应用于Java编程环境中,用于实现与HTTP服务器的通信。版本4.0.3是HttpClient的一个稳定版本,提供了丰富的功能和改进...