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

随机推荐

  1. android studio 使用cmake支持C++出现无
  2. Android(安卓)深入研究adb
  3. android 打开各种文件(setDataAndType)
  4. Android(安卓)保活后台启动Service 8.0踩
  5. Android(安卓)Camera 的学习记录
  6. This text field does not specify an in
  7. Android(安卓)Studio 导入项目时遇到sdk
  8. android布局属性之margin
  9. Android获取当前网络状态
  10. Android(安卓)BroadcastReceiver 简介