zoukankan      html  css  js  c++  java
  • 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() );
    
    
    

  • 相关阅读:
    模板方法模式
    策略模式
    代理模式
    单例模式
    工厂模式
    服务器负载过高问题分析
    支付宝APP支付开发- IOException : DerInputStream.getLength(): lengthTag=89, too big
    阿里云linux服务器挂载数据盘
    3.3.4.2选择特定行
    3.3.4.1选择所有数据
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7281386.html
Copyright © 2011-2022 走看看