//关于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单向认证
免责声明:文章转载自《JAVA实现https单向认证》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇马哥-docker 10节课程笔记Golang反射上篇下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=