javax.net.ssl.SSLException: hostname in certificate didn't match证书不匹配的主机名
来源:互联网 发布:会java学python 编辑:程序博客网 时间:2024/04/30 12:34
在使用org.apache.http库请求网络时,出现javax.net.ssl.sslexception:证书不匹配的主机名 的问题
如果只是使用org.apache.http的话下面的方法就够了,在进行请求时多加一行(同时记得导入):
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
protected String doInBackground(String... strings) {
final String url = strings[0];
//得到httpclient对象
DefaultHttpClient client = new DefaultHttpClient();
//封装get请求
HttpGet hg=new HttpGet(url);
//获取返回的response
try {
//修改org.apache.http的主机名验证解决问题
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
HttpResponse response = client.execute(hg);
//获取状态码
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode==200){
//entiry 里面封装的数据;
HttpEntity entity = response.getEntity();
//这个result就是json字符串,剩下的就是解析工作了;
String s = EntityUtils.toString(entity);
return s;
}
如果只是使用org.apache.http的话下面的方法就够了,在进行请求时多加一行(同时记得导入):
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
protected String doInBackground(String... strings) {
final String url = strings[0];
//得到httpclient对象
DefaultHttpClient client = new DefaultHttpClient();
//封装get请求
HttpGet hg=new HttpGet(url);
//获取返回的response
try {
//修改org.apache.http的主机名验证解决问题
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());
HttpResponse response = client.execute(hg);
//获取状态码
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode==200){
//entiry 里面封装的数据;
HttpEntity entity = response.getEntity();
//这个result就是json字符串,剩下的就是解析工作了;
String s = EntityUtils.toString(entity);
return s;
}
阅读全文
0 0
- 12. javax.net.ssl.SSLException: hostname in certificate didn't match证书不匹配的主机名
- javax.net.ssl.SSLException: hostname in certificate didn't match证书不匹配的主机名
- httpclient对象请求:如果报这个错:javax.net.ssl.SSLException: hostname in certificate didn't match证书不匹配的主机名
- javax.net.ssl.SSLException: hostname in certificate didn't match:
- javax.net.ssl.SSLException: hostname in certificate didn't match:
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- Android javax.net.ssl.SSLException: hostname in certificate didn't match...
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- HttpClient请求https,抛出javax.net.ssl.SSLException: hostname in certificate didn't match:
- HttpsURLConnection请求https,抛出javax.net.ssl.SSLException: hostname in certificate didn't match:
- HttpClient访问报错 javax.net.ssl.SSLException: hostname in certificate didn't match
- Android 异常:javax.net.ssl.SSLException: hostname in certificate didn't match
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- android SDK 更新出现“hostname in certificate didn't match: <dl-ssl.google.com>”解决方法
- android SDK 更新出现“hostname in certificate didn't match: <dl-ssl.google.com>”解决方法
- Android SDK下载异常(hostname in certificate didn't match)
- 洛谷 1928 外星密码 模拟? 解题报告
- 任务调度框架Quartz学习笔记—概述及第一个例子
- Python--操作excel之xlsxwriter
- LeetCode实战:动态规划算法是怎么一回事
- BZOJ 2815 浅谈有向图必经点问题总结+拓扑序+倍增LCA灭绝树求法
- javax.net.ssl.SSLException: hostname in certificate didn't match证书不匹配的主机名
- [爆]小程序内可直接打开网页了!附开发文档
- 五分钟读懂UML类图
- NODEJS全局配置以及环境配置
- Exynos4412 IIC总线驱动开发(一)—— IIC 基础概念及驱动架构分析
- Python学习笔记
- 互联网智能广告系统简易流程与架构
- AndroidStudio打印不出Log
- 函数命名