- 浏览: 143377 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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 922内部类的作用: 1.完善多重继承。 疑问在于:多重继承可以用 ... -
logBack用法,记录
2015-11-24 15:37 10011. Logback使用手册 系统中的日志采用 slf4j ... -
表产生sequence功能,测试并发
2015-11-18 16:21 627@Test public void testSerial ... -
Demo
2014-11-03 21:20 0package com.xly.jsoup.nbjy; /* ... -
反射小计
2014-10-07 11:32 499Test.java方法dd重载 class Test{ ... -
Btrace测试
2014-07-17 17:56 606偶尔看到BTrace,必须记录一下 利用hotSpot虚拟机 ... -
java对象占用heap的大小
2013-07-31 10:09 916一个对象占用的堆空间首先是和它有多少个成员变量直接相关 pub ... -
BeanCopier和BeanUtils实现对象复制,处理date类型
2013-03-29 12:52 4394没有废话 先是BeanUtils的实现类型: impo ... -
liferay 为JournalArticle添加分类
2013-03-21 15:45 1064/** * 为网页内容添加分类 ... -
liferay直接跳转到网页内容编辑页面修改的friendlyUrl效果
2013-03-21 14:11 1221找到portlat-impl.jar包,在目录 port ... -
JMS_DEMO
2013-03-14 20:25 14781.安装activeMq 修改service.pr ... -
Xmemcached/jedis springdemo
2013-02-20 13:13 901Xmemcached: HelloWordTest.ja ... -
规则检查功能的demo
2013-01-31 12:55 0规则检查Demo,包括mina,线程池功能 -
使用spring的线程安全web应用(翻译Thread-safe webapps using Spring)
2013-01-11 16:38 1885http://www.javalobby.org/articl ... -
JAVA虚拟机锁机制的升级流程
2013-01-08 14:52 2842http://ifeve.com/java-synchroni ... -
NIO学习
2012-11-27 11:49 1471最需要关注的是,应用进程、内核、IO三个概念。 所谓java的 ... -
Tomcat的HttpConnector/HttpProcesser(tomcat源码学习)
2012-11-21 10:47 1233先启动进程HttpProcesser,等请求到达后加入sock ... -
web.xml加载
2011-02-18 17:24 891转: web.xml文件内容加载顺序为:context- pa ... -
webLogic中 Cannot parse POST parameters of request: 的问题小记
2010-11-25 13:25 7773报错内容: weblogic.utils.NestedRunt ...
相关推荐
httpcomponents-jar包;httpcomponents-jar包;httpcomponents-jar包;httpcomponents-jar包;httpcomponents-jar包;httpcomponents-jar包
httpcomponents-client-4.5.2-bin.zip HttpComponents也就是以前的httpclient项目,可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端/服务器编程... 支持 HTTPS 协议 支持代理服务器等 支持Cookie
HttpComponents.zip HttpComponents.zip
httpcomponents-core-4.2.1 httpcomponents-client-4.2 httpcore4.2 org.apache.http
HttpComponents用法解析 Java模拟浏览器发送请求
apache-httpcomponents-httpmime.jar
里面包含httpcomponents所有jar包,足够开发使用的,很全面的,很好用!
httpcomponents apache开源http组件,主要用于相关http客户端通讯
httpclient httpget jar 包 下载
网络爬虫需要的org.apache.http包)(httpcomponents-client-4.2.5-bin.tar)
elasticsearch java low level rest client 所需的额外jar包
httpcomponents-client-4.5.4-osgi-bin.tar.gz 内含: org.apache.httpcomponents.httpclient_4.5.4.jar 官方说明: The Apache HttpComponents™ project is responsible for creating and maintaining a toolset ...
java-httpcomponents
Apache HttpComponents 已经取代了 HttpClient 。 官方内容:The Commons HttpClient project is now end of life, and is no longer being developed. It has been replaced by the Apache HttpComponents project ...
httpcomponents-client-4.2.5 源码+lib库
Apache HttpComponents提供HTTP接口,用来向目标网址提交HTTP请求,以获取网页的内容
Httpcomponents 是Apache Jakarta 項目的一個子項目 HttpComponents项目是HTTP协议的几个方面的底层库。在服务器或客户端通讯有高级需求的用户可能发现,对于建构定制的HTTP协议服务,这是一个有用的工具集
httpcomponents client apache开源源码基于httpcomponents-core,主要用于http客户端通讯
提供了可重用的客户端验证、HTTP状态管理、HTTP连接管理组件,简化HTTP客户端和服务器进行各种通信编程。
httpcomponents-client-4.2.5,httpcomponents-client-4.2.5,包括文档,代码示例亲测可用。