Android如何构建一个https请求的httpClient
来源:互联网 发布:mysql安装教程5.7.19 编辑:程序博客网 时间:2024/04/29 21:51
为了安全性的要求,有时候http请求需要通过https来访问,那么在Android上如何实现一个https的httpClient呢
实现方式如下:
public static HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore . getDefaultType()); trustStore.load( null, null); SSLSocketFactory sf = new SSLSocketFactory(trustStore); sf. setHostnameVerifier(SSLSocketFactory .ALLOW_ALL_HOSTNAME_VERIFIER ); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion. HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8) ; SchemeRegistry registry = new SchemeRegistry(); registry. register(new Scheme("http", PlainSocketFactory . getSocketFactory(), 80)); registry. register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager( params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
使用如上方法就可以建立一个Https的httpClient
0 0
- Android如何构建一个https请求的httpClient
- android 基于HttpClient的https请求
- Android 实现 HttpClient 请求Https
- android httpClient(https/http)的优化构建方式一
- android httpClient(https/http)的优化构建方式二
- Android中HttpClient请求https的验证过程
- android请求https(二)使用HttpClient 请求https
- Android支持https的处理方式1----httpclient请求https的处理方式
- android的HttpClient请求
- HttpClient请求Https协议
- HttpClient请求Https协议
- HttpClient请求Https协议
- HTTPClient 发送HTTPS请求
- java-httpclient-HTTPS请求
- HttpClient请求https
- httpClient发送https请求
- httpclient 实现https请求
- 关于httpclient 请求https (如何绕过证书验证)
- Assets目录下的文件大小是否有限制?
- Maximum Depth of Binary Tree (Leet Code)
- 关联容器
- cocoapods 0.35.0 版本 报错 Parsing unable to continue due to parsing error:
- ngrok服务端客户端编译
- Android如何构建一个https请求的httpClient
- HDU1029-Ignatius and the Princess IV
- 在ubuntu下安装python imagine library
- 如何使用富文本编辑器xheditor
- 【poj2575】Jolly Jumpers
- Extjs5 常用layout
- webview返回按钮 iOS
- 控制反转IOC(依赖注入DI),注入类型,自动装配相关注解
- getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用,getfilesdir