JAVA实现https单向认证
生活随笔
收集整理的这篇文章主要介绍了
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));//密匙库的passwordtrustStore.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单向认证的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 《HTML 5与CSS 3权威指南(第3
- 下一篇: DBI(i80)/DPI(RGB)/DS