android https之一
android https之二
android https之三
private HttpClient makeHttpsClient(String keyStorePasswd, int port) {try {KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());String trustStorePath = System.getProperty("javax.net.ssl.trustStore");// File keystoreFile = new File(trustStorePath);// 由于android权限原因,无法读取trustStorePath="//system/etc/security/cacerts.bks"文件,此处由sdcard代替File keystoreFile = new File("/sdcard/cacerts.bks");trustStore.load(new FileInputStream(keystoreFile), keyStorePasswd.toCharArray());SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);socketFactory.setHostnameVerifier(new X509HostnameVerifier() {public boolean verify(String host, SSLSession session) {return true;}public void verify(String host, SSLSocket ssl)throws IOException {}public void verify(String host, X509Certificate cert)throws SSLException {}public void verify(String host, String[] cns,String[] subjectAlts) throws SSLException {}});Scheme sch = new Scheme("https", socketFactory, port);HttpClient httpClient = new DefaultHttpClient();httpClient.getConnectionManager().getSchemeRegistry().register(sch);return httpClient;} catch (KeyStoreException e) {Log.e("xx", e.getMessage());} catch (NoSuchAlgorithmException e) {Log.e("xx", e.getMessage());} catch (CertificateException e) {Log.e("xx", e.getMessage());} catch (KeyManagementException e) {Log.e("xx", e.getMessage());} catch (UnrecoverableKeyException e) {Log.e("xx", e.getMessage());} catch (IOException e) {Log.e("xx", e.getMessage());}return null;}private void sendrequest() {try {HttpClient httpClient = makeHttpsClient("changeit", 8443);HttpPost httpPost = makeHttpPost("https://10.167.17.187:8443");HttpResponse response;response = httpClient.execute(httpPost);if (response != null) {Log.i("xx", "" + response.getStatusLine().getStatusCode());} else {Log.i("xx", "NULL");}} catch (ClientProtocolException e) {Log.e("xx", e.getMessage());} catch (IOException e) {Log.e("xx", e.getMessage());}}

更多相关文章

  1. Android几个面试题的解答
  2. Android(安卓)数据的读取与写入2
  3. Android(安卓)安全性和权限
  4. 浅析Android(安卓)手机卫士设备管理权限锁屏
  5. 【Android】设置android:maxLines="1"后,android:imeOptions="act
  6. 商品和oss
  7. logstash用kafka作为输入源
  8. Oracle的用户权限及其管理操作
  9. 循环读取数组

随机推荐

  1. Android培训班(17)
  2. androidのXlist框架上拉下拉刷新案例
  3. Android(安卓)3D壁纸开发设计
  4. EventBus源码解析(基于Android(安卓)O)
  5. 编译android
  6. android各个层次的理解
  7. Android开发常见错误及技巧
  8. address2line 定位 Android(安卓)c++奔溃
  9. android中使用百度定位sdk实时的计算移动
  10. Android(安卓)UI开发第三十篇——使用Fra