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());
}
}
分享到:
相关推荐
测试3种Android HTTPS网络访问
Sharp Sharp is a Scalable Vector ...https://github.com/pents90/svg-android Merged changes from forks: https://github.com/b2renger/svg-android https://github.com/mindon/svg-android https://github.com
《Android高薪之路:Android程序员面试宝典》目录: 第1章 Android入门 1 1 关于Android的非技术问题 1 1 1 为什么看好 Android 1 1 2 以前是否从事过Android的工作 做过哪些工作 1 1 3 你做的最复杂的界面是什么 1 ...
Android实现https网络访问,四种实现方式:1、客户端添加指定信任cer证书。2、客户端信任所有证书。3、HttpClient方式实现,支持所有Https免验证方式链接(与2类似,只不过采用HttpClient方式实现)。4、HttpClient...
Android Studio Chipmunk (2021.2.1) Beta 3 (android-studio-2021.2.1.10-mac_arm.zip)花栗鼠 适用于macOS Arm芯片系统,文件分割成两个压缩包,必须一起解压使用: Android Studio Chipmunk (android-studio-...
Android Studio Chipmunk (2021.2.1) Beta 3 (android-studio-2021.2.1.10-mac_arm.zip)花栗鼠 适用于macOS Arm芯片系统,文件分割成两个压缩包,必须一起解压使用: Android Studio Chipmunk (android-studio-...
Android Studio Chipmunk 2021.2.1(android-studio-2021.2.1.15-mac.dmg)花栗鼠 适用于macOS Intel芯片系统,文件使用WinRAR分割成两个压缩包,必须一起下载使用。在macOS使用WinZip进行解压: Android Studio ...
Android Studio Chipmunk (2021.2.1) Beta 2 (android-studio-2021.2.1.9-mac)花栗鼠 适用于macOS Intel芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: android-studio-2021.2.1.9-mac....
Android Studio Electric Eel 2022.1.1 Canary 2(android-studio-2022.1.1.2-mac.zip) 适用于macOS Intel系统,文件使用WinRAR分割两个压缩包,必须一起下载使用。在macOS使用WinZip进行解压: Android Studio ...
Android Studio Flamingo 2022.2.1(android-studio-2022.2.1.18-mac.dmg) 适用于macOS Intel芯片系统,文件使用WinRAR分割两个压缩包,必须一起下载使用。在macOS使用WinZip进行解压: Android Studio Flamingo...
Android Studio Chipmunk 2021.2.1(android-studio-2021.2.1.15-mac.dmg)花栗鼠 适用于macOS Intel芯片系统,文件使用WinRAR分割成两个压缩包,必须一起下载使用。在macOS使用WinZip进行解压: Android Studio ...
Android Studio Chipmunk (2021.2.1) Beta 3 (android-studio-2021.2.1.10-mac.zip)花栗鼠 适用于macOS Intel芯片系统,文件分割成两个压缩包,必须一起解压使用: Android Studio Chipmunk (android-studio-2021...
Android Studio Electric Eel 2022.1.1 Canary 2(android-studio-2022.1.1.2-mac.zip) 适用于macOS Intel系统,文件使用WinRAR分割两个压缩包,必须一起下载使用。在macOS使用WinZip进行解压: Android Studio ...
因为工作中要使用 Android Camera2 API 来实现相机功能,但因为Camera2比较复杂,网上资料也比较乱,有一定入门门槛,所以花了几天时间系统研究了下,这个项目就是我研究的成果。 其中包括一个自己写的Camera2的Demo...
Android Studio Chipmunk (2021.2.1) Beta 3 (android-studio-2021.2.1.10-mac.zip)花栗鼠 适用于macOS Intel芯片系统,文件分割成两个压缩包,必须一起解压使用: Android Studio Chipmunk (android-studio-2021...
Android Studio Chipmunk 2021.2.1(android-studio-2021.2.1.15-mac_arm.dmg)花栗鼠 适用于macOS Arm芯片系统,文件使用WinRAR分割成两个压缩包,必须一起下载使用。在macOS使用WinZip进行解压: AndroidStudio ...
Android Studio Chipmunk (2021.2.1) Beta 2 (android-studio-2021.2.1.9-mac_arm)花栗鼠 适用于macOS Arm芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: android-studio-2021.2.1.9-mac_...
android-studio-2021.3.1.3-mac.part2.rar https://download.csdn.net/download/weixin_43800734/81092319 Android Studio版本排序: Dolphin | 2021.3.1 Chipmunk | 2021.2.1 Bumblebee | 2021.1.1 Arctic Fox | ...
相关博客:【android学习开源项目之AndroidAutoSize】AndroidAutoSize和DialogFragment的适配 https://blog.csdn.net/ljb568838953/article/details/103906449; 本demo的知识点:1.AndroidAutoSize 的使用(今日...
Android Studio Chipmunk (2021.2.1) Beta 2 (android-studio-2021.2.1.9-mac_arm)花栗鼠 适用于macOS Arm芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: android-studio-2021.2.1.9-mac_...