JAVA实现https单向认证

摘要:
它可以用多种方式书写。
//关于http 须要两个jar包   httpclient-4.0.jar	httpcore-4.0.1.jar
private static final HttpClient httpClient = new DefaultHttpClient();

	try {
			//获得密匙库
		KeyStore trustStore = KeyStore.getInstance("jks");
		String keyStoreFile = "xxxxx.keystore";
	        String keyPwd =  "xxxxxxx";
		FileInputStream instream = new FileInputStream(new File(keyStoreFile));
	        //密匙库的password
	        trustStore.load(instream, keyPwd.toCharArray());
	        //注冊密匙库
	        SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
	        //不校验域名
	        socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
	        Scheme sch = new Scheme("https", socketFactory, 443);
	        httpClient.getConnectionManager().getSchemeRegistry().register(sch);
		} catch (Exception e) {
			e.printStackTrace();
		}
//以下这段是调用代码。能够有非常多种写法。不局限于用HttpPost
HttpPost httpPost = new HttpPost( url );
StringEntity entity = new StringEntity(params);
entity.setContentEncoding("UTF-8");
httpPost.setEntity( entity );
//发送请求
HttpResponse response = httpClient.execute( httpPost );
String jsonStr = EntityUtils.toString( response.getEntity() );



免责声明:文章转载自《JAVA实现https单向认证》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇马哥-docker 10节课程笔记Golang反射上篇下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

基于kubernetes实现链路监控

介绍 官方文档:https://skywalking.apache.org/docs/main/latest/readme/ chart包地址:https://github.com/apache/skywalking-kubernetes 实践 Install released version using Helm repository 下载cha...

SuperSocket 2.0 发布第一个预览版, 另寻找Yang Fan哥哥

昨天,SuperSocket的作者发布了2.0版本的第一个预览版。SuperSocket 2.0 是一个经过全新设计的,第一个完全基于.NET Core的版本。作者正在积极尝试提供更简单易用的API的同时,尽量保证与老版本相似的原汁原味的开发体验。新的版本中亦删除了一些不太重要并且已有更好的替代实现的功能,例如服务器宿主。 时隔三年之后再次发布新的版本,意...

idea git 配置代理

idea需要git操作的这样配置代理,在当前项目目录进入命令行: 配置全局参数:--global 代理 :git config --global http.proxy http://192.168.15.40:3128取消代理: git config --global --unset http.proxy查询是否使用:git config --global...

安装python3

一.编译python3: 1、安装或依赖包:yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make 2、wgethttps://www.python.org/ftp/python/3.6.6/Py...

Docker部署Zabbix+Grafana监控

Docker部署Zabbix+Grafana监控 环境 centos 7 ; Docker 17.12.0-ce ; docker-compose version 1.20.1 2018-4-1 当前zabbix最新版3.4.7 ,grafana最新版5.0.4 #下载部署代码 cd /opt git clone https://gitee.com/a...

idea双击打不开没反应的解决办法

   原文链接:https://www.cnblogs.com/jiazibo/p/14618483.html 网上找了很多方法最后才找到一个可以解决的,如果遇到的问题与我这个相同可以用这个方法解决 1.打开idea安装根目录bin下,选中idea.bat右键编辑,或者使用txt打开 2.在idea.bat最后一行添加 pause  如图   3....