- 浏览: 278414 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
tan_1208815066:
传送pdf 的文件 不能正确的 传送
试试用Socket传文件 -
richardri:
结果是0怎么解决?支持mov、mp4、3gp吗?
JAVA獲取視頻文件的播放長度 -
zhujia130:
xiaoyaodandan 写道结果是0.。。。。。你给的路径 ...
JAVA獲取視頻文件的播放長度 -
xiaoyaodandan:
结果是0.。。。。。
JAVA獲取視頻文件的播放長度 -
flowerjacky:
明了
Java事务处理类
Components
This example demonstrates how to send an HTTP request via a proxy.
请求通过一个代理
这个例子示范怎样去发送一个HTTP请求通过一个代理
package cn.lake.util; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; import org.apache.http.client.HttpClient; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.scheme.SocketFactory; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.message.BasicHttpRequest; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; import org.apache.http.util.EntityUtils; /** * How to send a request via proxy using {@link HttpClient HttpClient}. * * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> * * * <!-- empty lines above to avoid 'svn diff' context problems --> * @version $Revision$ * * @since 4.0 */ public class ClientExecuteProxy { /** * The default parameters. * Instantiated in {@link #setup setup}. */ private static HttpParams defaultParameters = null; /** * The scheme registry. * Instantiated in {@link #setup setup}. */ private static SchemeRegistry supportedSchemes; /** * Main entry point to this example. * * @param args ignored */ public final static void main(String[] args) throws Exception { // make sure to use a proxy that supports CONNECT final HttpHost target = new HttpHost("issues.apache.org", 443, "https"); final HttpHost proxy = new HttpHost("127.0.0.1", 8666, "http"); setup(); // some general setup HttpClient client = createHttpClient(); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpRequest req = createRequest(); System.out.println("executing request to " + target + " via " + proxy); HttpEntity entity = null; try { HttpResponse rsp = client.execute(target, req); entity = rsp.getEntity(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); Header[] headers = rsp.getAllHeaders(); for (int i = 0; i < headers.length; i++) { System.out.println(headers[i]); } System.out.println("----------------------------------------"); if (rsp.getEntity() != null) { System.out.println(EntityUtils.toString(rsp.getEntity())); } } finally { // If we could be sure that the stream of the entity has been // closed, we wouldn't need this code to release the connection. // However, EntityUtils.toString(...) can throw an exception. // if there is no entity, the connection is already released if (entity != null) entity.consumeContent(); // release connection gracefully } } // main private final static HttpClient createHttpClient() { ClientConnectionManager ccm = new ThreadSafeClientConnManager(getParams(), supportedSchemes); // new SingleClientConnManager(getParams(), supportedSchemes); DefaultHttpClient dhc = new DefaultHttpClient(ccm, getParams()); return dhc; } /** * Performs general setup. * This should be called only once. */ private final static void setup() { supportedSchemes = new SchemeRegistry(); // Register the "http" and "https" protocol schemes, they are // required by the default operator to look up socket factories. SocketFactory sf = PlainSocketFactory.getSocketFactory(); supportedSchemes.register(new Scheme("http", sf, 80)); sf = SSLSocketFactory.getSocketFactory(); supportedSchemes.register(new Scheme("https", sf, 80)); // prepare parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF-8"); HttpProtocolParams.setUseExpectContinue(params, true); defaultParameters = params; } // setup private final static HttpParams getParams() { return defaultParameters; } /** * Creates a request to execute in this example. * * @return a request without an entity */ private final static HttpRequest createRequest() { HttpRequest req = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); //("OPTIONS", "*", HttpVersion.HTTP_1_1); return req; } }
翻譯不好,請見諒!
发表评论
-
junit实现测试类(在Spring2.5中)
2009-01-17 15:14 2412第一步: 创建JAVA项目,也可以是Web项目,加入Sprin ... -
HttpClient Examples:Custom protocol interceptors
2009-01-15 14:06 1512官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Custom SSL context
2009-01-15 13:58 2032官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Threaded request execution
2009-01-15 13:54 1482官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Form based logon
2009-01-15 13:49 2006官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Custom execution context
2009-01-15 13:46 1556官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Chunk encoded POST
2009-01-15 12:36 2189官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Proxy authentication
2009-01-15 12:26 1395官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Abort method
2009-01-15 12:06 1597官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Manual connection release
2009-01-15 11:54 1198官方主頁:http://hc.apache.org/ Co ... -
HttpClient Examples:Response handling
2009-01-15 11:44 2334官方主頁:http://hc.apache.org/ Co ... -
使用commons-codec包加密字符串(MD5,SHA1,BASE64)
2009-01-13 13:56 8237commons-codec包可以从apache下载,最新版是1 ... -
Java对称加密编码:BESA64
2009-01-13 10:58 2509package cn.lake.util; import s ... -
Java对称加密编码:IDEA
2009-01-13 10:55 2124package cn.lake.util; /** * J ... -
用java获得你电脑中的cpu数量
2009-01-13 10:41 2380System.out.println("你的电脑cp ... -
JAVA的国际化问题讨论
2008-12-18 15:05 1059一切有一个问题相当苦脑:JAVA的国际化问题; 如 ... -
客户请求的浏览器类型
2008-12-17 00:17 926<td width="50%"> ... -
同时启动多个resion
2008-12-09 15:55 1016在本地同时启动多个Resin,要修改2个文件,总共是3个处 一 ... -
JSP基本语法加实例
2008-12-09 13:38 1618应作者要求:【转】http://www.cnblogs.com ... -
struts标签logic
2008-12-08 16:32 1550<!--######################## ...
相关推荐
在使用Apache HttpClient进行HTTP通信时,可能会遇到"HttpClient问题:The server failed to respond with a valid HTTP resp"这样的异常。这个错误通常表示服务器未能返回一个有效的HTTP响应,这可能是由多种原因...
《Apache Commons HttpClient 3.1详解》 Apache Commons HttpClient 是一个功能强大的Java库,专为实现客户端HTTP通信而设计。这个3.1版本是HttpClient的一个重要里程碑,它提供了丰富的功能和改进,使得开发者能够...
Maven坐标:org.apache.httpcomponents:httpclient:4.5.12; 标签:apache、httpcomponents、httpclient、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档...
Maven坐标:org.apache.httpcomponents:httpclient:4.5.13; 标签:apache、httpcomponents、httpclient、jar包、java、中文文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档...
Maven坐标:org.apache.httpcomponents:httpclient:4.5.13; 标签:apache、httpcomponents、httpclient、jar包、java、中英对照文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览...
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods....
本文将深入探讨如何在Android中使用HttpClient进行代理设置,并结合具体的例子来阐述相关知识点。 首先,了解`HttpClient`是Apache的一个开源库,它提供了一个强大的、功能丰富的HTTP客户端API,使得开发者可以方便...
标题中的"commons-httpclient3.1.jar,commons-codec1.3.jar,commons-logging1.1.1.jar"指的是三个关键的Java库文件,它们是Apache HttpClient项目的一部分,用于在Java应用程序中实现HTTP通信。这些JAR(Java ...
《Apache Commons HttpClient 3.1:HTTP客户端编程的基石》 ...然而,需要注意的是,HttpClient 3.1已不再维护,最新的稳定版本为HttpClient 4.x,对于新项目建议使用更现代的版本以获取更好的性能和兼容性。
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....
HttpResponse response = httpClient.execute(request); ``` 现在,我们转向主题——忽略SSL验证。在生产环境中,SSL验证是必须的,以确保数据传输的安全性。但在开发或测试环境中,我们可能需要绕过这一环节。...
赠送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 ...
《HttpClient 4.5详解与应用实践》 HttpClient是一个开源的Java库,由Apache软件基金会维护,主要用于在HTTP协议上实现客户端的通信。版本4.5是HttpClient的一个稳定版本,提供了许多增强的功能和优化,使其成为...
ribbon-httpclient-2.2.5.jar
- 创建 HttpClient 实例:首先,我们需要创建一个 HttpClient 实例,这可以通过 HttpClientBuilder 或直接使用 HttpClients.createDefault() 方法完成。 - 创建请求:然后,我们需要构造一个 HttpRequestBase 对象...
Request是对httpclient的封装,类似于python的request库,用法Request.Get(pictureUrl).execute().returnContent().toString();需要以来httpclient和httpcore包。2020年1月更新。
此外,HttpClient还支持异步操作,可以在多线程环境中高效地处理并发请求。 2. **httpcore-4.4.12.jar**:这是HttpClient的核心库,包含了HTTP协议的基本组件,如连接管理、请求和响应模型、编码器和解码器等。...
《JAVA中使用HttpClient:commons-httpclient-3.0.jar详解》 在JAVA开发中,进行HTTP请求时,Apache的HttpClient库是一个不可或缺的工具。本文将深入解析`commons-httpclient-3.0.jar`,它是HttpClient的一个重要...
码头ReactiveStream HttpClient 围绕的包装器。...// Create a request using the HttpClient APIs.Request request = httpClient . newRequest( " http://localhost:8080/path " );// Wrap the request using the
在这个版本中,我们关注的是`httpclient-4.5.jar`,这是一个包含了HttpClient 4.5核心功能的Java库。这个库的发布日期为2016年7月19日,它提供了许多改进和新特性,旨在帮助开发者更高效、更稳定地构建网络应用程序...