- 浏览: 272967 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
tan_1208815066:
传送pdf 的文件 不能正确的 传送
试试用Socket传文件 -
richardri:
结果是0怎么解决?支持mov、mp4、3gp吗?
JAVA獲取視頻文件的播放長度 -
zhujia130:
xiaoyaodandan 写道结果是0.。。。。。你给的路径 ...
JAVA獲取視頻文件的播放長度 -
xiaoyaodandan:
结果是0.。。。。。
JAVA獲取視頻文件的播放長度 -
flowerjacky:
明了
Java事务处理类
Components
This example shows the use of protocol interceptors to transparently modify properties of HTTP messages sent / received by the HTTP client.
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 HttpClient interface.
自定义拦截协议
这个例子表明使用协议拦截透过修改属性的HTTP邮件发送/接收的HTTP客户端。
在这种特定情况下的HTTP客户端是能够透过内容gzip压缩增加了两个议定书拦截:请求拦截,增加了'接受编码: gzip或'标头所有即将离任的要求和反应,它可以自动拦截扩展压缩响应这些实体的包装与uncompressing装饰类。使用协议拦截使得完全透明的内容压缩到消费者的HttpClient接口。
package cn.lake.util; import java.io.IOException; import java.io.InputStream; import java.util.zip.GZIPInputStream; 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.methods.HttpGet; import org.apache.http.entity.HttpEntityWrapper; 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(); 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(); 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://www.apache.org/"); // 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()); } } static class GzipDecompressingEntity extends HttpEntityWrapper { public GzipDecompressingEntity(final HttpEntity entity) { super(entity); } @Override public InputStream getContent() throws IOException, IllegalStateException { // the wrapped entity's getContent() decides about repeatability InputStream wrappedin = wrappedEntity.getContent(); return new GZIPInputStream(wrappedin); } @Override public long getContentLength() { // length of ungzipped content is not known return -1; } } }
翻譯的不好,請見諒!
发表评论
-
junit实现测试类(在Spring2.5中)
2009-01-17 15:14 2370第一步: 创建JAVA项目,也可以是Web项目,加入Sprin ... -
HttpClient Examples:Custom SSL context
2009-01-15 13:58 2002官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Threaded request execution
2009-01-15 13:54 1442官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Form based logon
2009-01-15 13:49 1968官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Custom execution context
2009-01-15 13:46 1518官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Chunk encoded POST
2009-01-15 12:36 2146官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Proxy authentication
2009-01-15 12:26 1342官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Request via a proxy
2009-01-15 12:19 2173官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Abort method
2009-01-15 12:06 1564官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Manual connection release
2009-01-15 11:54 1150官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Response handling
2009-01-15 11:44 2273官方主頁:http://hc.apache.org/ Co ... -
使用commons-codec包加密字符串(MD5,SHA1,BASE64)
2009-01-13 13:56 8179commons-codec包可以从apache下载,最新版是1 ... -
Java对称加密编码:BESA64
2009-01-13 10:58 2450package cn.lake.util; import s ... -
Java对称加密编码:IDEA
2009-01-13 10:55 2083package cn.lake.util; /** * J ... -
用java获得你电脑中的cpu数量
2009-01-13 10:41 2326System.out.println("你的电脑cp ... -
JAVA的国际化问题讨论
2008-12-18 15:05 1037一切有一个问题相当苦脑:JAVA的国际化问题; 如 ... -
客户请求的浏览器类型
2008-12-17 00:17 880<td width="50%"> ... -
同时启动多个resion
2008-12-09 15:55 990在本地同时启动多个Resin,要修改2个文件,总共是3个处 一 ... -
JSP基本语法加实例
2008-12-09 13:38 1579应作者要求:【转】http://www.cnblogs.com ... -
struts标签logic
2008-12-08 16:32 1513<!--######################## ...
相关推荐
import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory; import org.apache.commons.httpclient.util.HttpURLConnection;
JAVAHttpClientThe server failed to respond with a validCaused by: org.apache.htt
Maven坐标:org.apache.httpcomponents:httpclient:4.5.13; 标签:apache、httpcomponents、httpclient、jar包、java、中文文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档...
赠送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 ...
只是jar包
ribbon-httpclient-2.2.5.jar
wechatpay-apache-httpclient 概览 的扩展,实现了请求签名的生成和应答签名的验证。...implementation 'com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.2.2' Maven 加入以下依赖 <groupId>com.github.w
下面给大家展示了AndroidHttpClient结构: public final class AndroidHttpClient extends Object implements HttpClient 前言: 这类其实是Google对阿帕奇的HttpClient的一个封装,一些默认属性有android做了一些...
Maven坐标:org.apache.httpcomponents:httpclient:4.5.6; 标签:apache、httpcomponents、httpclient、jar包、java、中文文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档...
Maven坐标:org.apache.httpcomponents:httpclient:4.5.13; 标签:apache、httpcomponents、httpclient、jar包、java、中英对照文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览...
基于c++11 httpclient https://github.com/iEternity/HttpClient github上是基于win的,附件为linux平台,以及android源码环境生成的主机host bin程序,在android 8.1,linux14.04环境均编译通过 内含CMakelists ...
httpclient-4.3.1.jar httpcore-4.4.13.jar commons-logging-1.2.jar
HttpClientUtil 一个Http请求使用HttpClient访问服务器,我们也可以将文件上传到服务器,例如文件或图片。它提供了在您的上传过程中更新进度的接口。
Maven坐标:org.apache.httpcomponents:httpclient:4.2.5; 标签:apache、httpcomponents、httpclient、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档...
Maven坐标:org.apache.httpcomponents:httpclient:4.5.10; 标签:apache、httpcomponents、httpclient、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档...
commons-httpclient-3.0.jar JAVA中使用HttpClient可以用到
Maven坐标:org.apache.httpcomponents:httpclient:4.4; 标签:apache、httpcomponents、httpclient、jar包、java、API文档、中文版; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览...
Maven坐标:org.apache.httpcomponents:httpclient:4.5.12; 标签:apache、httpcomponents、httpclient、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档...
easy-httpclient Author: Zlatan W HO(何为)
Maven坐标:org.apache.httpcomponents:httpclient:4.4.1; 标签:apache、httpcomponents、httpclient、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览...