標籤:efault print toc private client getc jar div rust
//關於http 須要兩個jar包 httpclient-4.0.jarhttpcore-4.0.1.jarprivate 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();}//以下這段是調用代碼。能夠有非常多種寫法。不局限於用HttpPostHttpPost 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單向認證