- 浏览: 146666 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (95)
- java (25)
- 数据库 (9)
- js (0)
- 框架 (10)
- 小问题 (8)
- 转载 (2)
- 配置开发环境 (6)
- 其它 (4)
- 功能记录 (2)
- 安全 (1)
- shell (3)
- spring ibaitis struts2 redis desc (1)
- spring security3.1 (1)
- 小问题 环境 (1)
- 小问题 环境 DelegatingFilterProxy cannot be cast to Filter (0)
- redis filter java (1)
- java redis (2)
- spring quartz 集群 批处理 (1)
- java mybatis (1)
- Junit soap (1)
- mock junit (0)
- mock junit spring (1)
- java jsoup (0)
- jsoup (1)
- python27 pycharm (1)
- maven pom (1)
- java log (1)
- mybatis 分页 (1)
- mysql (1)
- 业务 (1)
- java 测试 (1)
- java zookeeper 批处理 (1)
- hive hadoop (1)
- hive (1)
- hadoop (1)
- maven archetype (1)
- python rsa (1)
- python 页面分析 (1)
- python (0)
最新评论
-
wuyafeng123:
秒杀活动设计思路 -
indiajohns:
非常感谢,很快解决了我的问题
jmesa查询条件中文的编码转换问题 -
yujiaao:
太好了,感谢啊!这行在我这好象不行:URLDecoder.de ...
jmesa查询条件中文的编码转换问题 -
michael_wong:
呵呵,找到啦。在这里有全部源码:http://ishare. ...
Maven权威指南 的simple-parent 工程源码 -
michael_wong:
我也在找啊
Maven权威指南 的simple-parent 工程源码
用于发送https请求,不需要对服务器的CA认证
http://hc.apache.org/httpcomponents-client/tutorial/html/connmgmt.html#d4e470
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;//
import java.security.cert.CertificateException;//
import java.security.cert.X509Certificate;//
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;//注意导入
import javax.servlet.http.HttpServletRequest;//注意导入
import javax.servlet.http.HttpServletResponse;//注意导入
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.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
public class HttpClintUrlTool {
private HttpServletRequest request;
private HttpServletResponse response;
private String urlconn;
private String params;
public void send(String address) throws Exception {
DefaultHttpClient httpclient0 = new DefaultHttpClient();
DefaultHttpClient httpclient=useTrustingTrustManager(httpclient0);//关键方法
HttpGet httpget = new HttpGet(this.urlconn);
// Execute HTTP request
// System.out.println("executing request " + httpget.getURI());
HttpResponse response = httpclient.execute(httpget);
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
if (entity != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
try {
System.out.println(reader.readLine());
} catch (IOException ex) {
throw ex;
} catch (RuntimeException ex) {
httpget.abort();
throw ex;
} finally {
reader.close();
}
}
httpclient.getConnectionManager().shutdown();
}
/**
*
* @param httpClient
* @return
*/
public static DefaultHttpClient useTrustingTrustManager(DefaultHttpClient httpClient)
{
try
{
// First create a trust manager that won't care.
X509TrustManager trustManager = new X509TrustManager()
{
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException
{
// Don't do anything.
}
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException
{
// Don't do anything.
}
public X509Certificate[] getAcceptedIssuers()
{
// Don't do anything.
return null;
}
};
// Now put the trust manager into an SSLContext.
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[] { trustManager }, null);
// Use the above SSLContext to create your socket factory
// (I found trying to extend the factory a bit difficult due to a
// call to createSocket with no arguments, a method which doesn't
// exist anywhere I can find, but hey-ho).
SSLSocketFactory sf = new SSLSocketFactory(sslcontext);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
// If you want a thread safe client, use the ThreadSafeConManager, but
// otherwise just grab the one from the current client, and get hold of its
// schema registry. THIS IS THE KEY THING.
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry schemeRegistry = ccm.getSchemeRegistry();
// Register our new socket factory with the typical SSL port and the
// correct protocol name.
schemeRegistry.register(new Scheme("https", sf, 443));
// Finally, apply the ClientConnectionManager to the Http Client
// or, as in this example, create a new one.
return new DefaultHttpClient(ccm, httpClient.getParams());
}
catch(Throwable t)
{
// AND NEVER EVER EVER DO THIS, IT IS LAZY AND ALMOST ALWAYS WRONG!
t.printStackTrace();
return null;
}
}
}
http://hc.apache.org/httpcomponents-client/tutorial/html/connmgmt.html#d4e470
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;//
import java.security.cert.CertificateException;//
import java.security.cert.X509Certificate;//
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;//注意导入
import javax.servlet.http.HttpServletRequest;//注意导入
import javax.servlet.http.HttpServletResponse;//注意导入
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.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
public class HttpClintUrlTool {
private HttpServletRequest request;
private HttpServletResponse response;
private String urlconn;
private String params;
public void send(String address) throws Exception {
DefaultHttpClient httpclient0 = new DefaultHttpClient();
DefaultHttpClient httpclient=useTrustingTrustManager(httpclient0);//关键方法
HttpGet httpget = new HttpGet(this.urlconn);
// Execute HTTP request
// System.out.println("executing request " + httpget.getURI());
HttpResponse response = httpclient.execute(httpget);
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
if (entity != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
try {
System.out.println(reader.readLine());
} catch (IOException ex) {
throw ex;
} catch (RuntimeException ex) {
httpget.abort();
throw ex;
} finally {
reader.close();
}
}
httpclient.getConnectionManager().shutdown();
}
/**
*
* @param httpClient
* @return
*/
public static DefaultHttpClient useTrustingTrustManager(DefaultHttpClient httpClient)
{
try
{
// First create a trust manager that won't care.
X509TrustManager trustManager = new X509TrustManager()
{
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException
{
// Don't do anything.
}
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException
{
// Don't do anything.
}
public X509Certificate[] getAcceptedIssuers()
{
// Don't do anything.
return null;
}
};
// Now put the trust manager into an SSLContext.
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[] { trustManager }, null);
// Use the above SSLContext to create your socket factory
// (I found trying to extend the factory a bit difficult due to a
// call to createSocket with no arguments, a method which doesn't
// exist anywhere I can find, but hey-ho).
SSLSocketFactory sf = new SSLSocketFactory(sslcontext);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
// If you want a thread safe client, use the ThreadSafeConManager, but
// otherwise just grab the one from the current client, and get hold of its
// schema registry. THIS IS THE KEY THING.
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry schemeRegistry = ccm.getSchemeRegistry();
// Register our new socket factory with the typical SSL port and the
// correct protocol name.
schemeRegistry.register(new Scheme("https", sf, 443));
// Finally, apply the ClientConnectionManager to the Http Client
// or, as in this example, create a new one.
return new DefaultHttpClient(ccm, httpClient.getParams());
}
catch(Throwable t)
{
// AND NEVER EVER EVER DO THIS, IT IS LAZY AND ALMOST ALWAYS WRONG!
t.printStackTrace();
return null;
}
}
}
发表评论
-
详解ReentrantReadWriteLock
2016-04-21 14:34 0package java.util.concurrent. ... -
java内部类使用场景体会
2016-04-21 11:56 967内部类的作用: 1.完善多重继承。 疑问在于:多重继承可以用 ... -
logBack用法,记录
2015-11-24 15:37 10321. Logback使用手册 系统中的日志采用 slf4j ... -
表产生sequence功能,测试并发
2015-11-18 16:21 662@Test public void testSerial ... -
Demo
2014-11-03 21:20 0package com.xly.jsoup.nbjy; /* ... -
反射小计
2014-10-07 11:32 529Test.java方法dd重载 class Test{ ... -
Btrace测试
2014-07-17 17:56 641偶尔看到BTrace,必须记录一下 利用hotSpot虚拟机 ... -
java对象占用heap的大小
2013-07-31 10:09 953一个对象占用的堆空间首先是和它有多少个成员变量直接相关 pub ... -
BeanCopier和BeanUtils实现对象复制,处理date类型
2013-03-29 12:52 4497没有废话 先是BeanUtils的实现类型: impo ... -
liferay 为JournalArticle添加分类
2013-03-21 15:45 1115/** * 为网页内容添加分类 ... -
liferay直接跳转到网页内容编辑页面修改的friendlyUrl效果
2013-03-21 14:11 1267找到portlat-impl.jar包,在目录 port ... -
JMS_DEMO
2013-03-14 20:25 15231.安装activeMq 修改service.pr ... -
Xmemcached/jedis springdemo
2013-02-20 13:13 932Xmemcached: HelloWordTest.ja ... -
规则检查功能的demo
2013-01-31 12:55 0规则检查Demo,包括mina,线程池功能 -
使用spring的线程安全web应用(翻译Thread-safe webapps using Spring)
2013-01-11 16:38 1919http://www.javalobby.org/articl ... -
JAVA虚拟机锁机制的升级流程
2013-01-08 14:52 2882http://ifeve.com/java-synchroni ... -
NIO学习
2012-11-27 11:49 1516最需要关注的是,应用进程、内核、IO三个概念。 所谓java的 ... -
Tomcat的HttpConnector/HttpProcesser(tomcat源码学习)
2012-11-21 10:47 1274先启动进程HttpProcesser,等请求到达后加入sock ... -
web.xml加载
2011-02-18 17:24 918转: web.xml文件内容加载顺序为:context- pa ... -
webLogic中 Cannot parse POST parameters of request: 的问题小记
2010-11-25 13:25 7834报错内容: weblogic.utils.NestedRunt ...
相关推荐
6. **支持HTTPS**:内置SSL/TLS支持,能够安全地进行加密通信,确保数据传输的安全性。 三、使用示例 在实际开发中,我们可以通过以下步骤使用HTTPComponents Client 4.5.5发送HTTP请求: 1. 创建HttpClient实例...
4. **HTTPS支持**:集成SSL/TLS,支持安全的HTTPS通信。 5. **多线程和并发**:库本身是线程安全的,可以方便地在多线程环境中使用。 6. **国际化与本地化**:支持多种字符集编码,适应不同地区的网络环境。 三、...
HttpComponents是Java领域中用于处理HTTP协议的重要库,它提供了对HTTP协议的强大支持,包括HTTP请求的发送、响应的接收以及各种复杂的HTTP操作。 描述中提到的几个文件是HttpComponents客户端的核心组件: 1. ...
httpcomponents-client-4.5.2-bin.zip HttpComponents也就是以前的httpclient项目,可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端/服务器编程... 支持 HTTPS 协议 支持代理服务器等 支持Cookie
在处理HTTPS请求时,HTTPComponents Client提供了强大的安全性保障。它支持SSL/TLS协议,可以配置信任的证书和密钥库。同时,4.2.5版本包含了多种身份验证机制,如Basic Auth、Digest Auth和NTLM,以应对不同服务器...
5. **安全性**:HttpComponents Core支持多种安全协议,如SSL/TLS,可以实现HTTPS的安全通信。同时,它还支持多种认证机制,如Basic、Digest、NTLM等,确保数据传输的安全性。 6. **国际化与本地化**:库中的组件...
它不仅提供了标准的GET、POST等HTTP方法,还支持更高级的特性,如分块传输编码、管道连接、代理服务器交互、HTTPS安全通信等。此外,该库允许开发者自定义请求头,以满足各种复杂的网络请求需求。 三、连接管理 在...
7. **HTTPS支持**:对于安全的HTTPS通信,HttpComponents Client提供了内置的SSL/TLS支持,用户可以通过`SSLSocketFactory`和`KeyManagers`等来配置证书和密钥材料。 8. **多路复用(HTTP/2)**:虽然4.1.2版本不...
这个版本提供了丰富的功能,包括支持HTTPS、Cookie管理、多线程请求、身份验证、自动重定向等。通过HttpClient,开发者可以方便地构建复杂的HTTP请求,如POST、PUT、DELETE等,同时支持自定义请求头和实体内容。...
5. **安全性和认证**:库内集成了SSL/TLS支持,可以创建安全的HTTPS连接。同时,它还提供了多种认证机制,如Basic、Digest、NTLM和Kerberos等,方便在不同环境中进行身份验证。 6. **自定义扩展**:HttpComponents ...
对于HTTPS支持,HTTPComponents Core依赖于`SSLContext`和`SSLSocketFactory`,可以配置各种安全策略。`SecureProtocolSocketFactory`接口允许用户自定义安全套接层的实现。 七、扩展性与模块化 HTTPComponents ...
此外,它还提供了对HTTPS的支持,可以处理SSL/TLS连接。 9. **Asynchronous Programming**:除了同步API外,HttpClient 4.5.1还提供了异步API,使得开发者能够在非阻塞模式下执行HTTP请求,适合于高并发场景。 10....
6. **安全性**:支持HTTPS协议,可以配置SSL/TLS参数,实现安全的数据传输。 二、主要组件 1. **HttpClient**:核心组件,负责发起HTTP请求,管理连接池,处理响应。 2. **HttpCore**:底层通信引擎,提供低级别...
此外,它还包含了对HTTPS协议的支持,使得开发者可以安全地进行网络通信。 在Android开发中,由于系统自带的HttpURLConnection类在某些情况下性能不佳或者功能不足,开发者往往选择使用HttpComponents Core作为替代...
这个库是Java开发者用来构建HTTP客户端应用的重要工具,它提供了全面的功能来处理HTTP协议,包括GET、POST以及其他HTTP方法,支持HTTPS安全连接,以及各种HTTP特性如重定向、Cookie管理等。 描述中的...
1. **多协议支持**:HttpClient不仅支持HTTP/1.1,还对HTTP/2进行了部分支持,同时兼容HTTPS,提供安全的数据传输。 2. **异步与同步API**:HttpClient提供了同步和异步两种API,可以满足不同场景的需求。同步API...
4. **HttpClient Transport**:包含了多种传输机制,如基于NIO的传输,以及对HTTPS的支持。 5. **Authentication and Authorization**:提供了HTTP认证和授权的相关库,支持多种标准的认证机制,如Basic、Digest、...
同时,对于HTTPS支持,HttpClient提供了SSLContext和SSLSocketFactory配置,允许开发者自定义证书信任和加密算法,确保了通信的安全性。 五、异步与多线程 除了传统的同步执行模式,HttpClient还提供了异步执行能力...
该库不仅提供了基本的HTTP功能,还支持HTTPS、代理、重定向、身份验证等多种高级特性,是Java开发中不可或缺的工具之一。在实际项目中,你可以根据具体需求调整配置,优化性能,确保网络通信的稳定性和安全性。
3. **身份验证与安全**:支持多种认证机制,如Basic, Digest, NTLM, Kerberos等,并且对SSL/TLS有深度集成,可以进行安全的HTTPS通信。 4. **请求与响应处理**:提供了灵活的接口来构建和发送HTTP请求,解析和处理...