Android https服务器连接无对等点

发布于 2024-12-29 19:48:13 字数 1208 浏览 1 评论 0原文

我正在开发 Android 应用程序,它通过 https 连接连接到服务器。 我已经使用受信任的证书创建了 my_store.bks 文件,并使用以下代码连接到服务器:

DefaultHttpClient httpclient = new DefaultHttpClient();
KeyStore trustStore  = KeyStore.getInstance("BKS");
InputStream in = context.getResources().openRawResource(R.raw.my_store);
try{ 
  trustStore.load(in,pass.toCharArray());
}
catch(Exception e){
  Log.v("MyLog", "errror reading sert: " + e.toString());
}
finally{
  in.close();
}
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);


HttpPost poster = new HttpPost(serverAdress);
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(formparams,"UTF-8");
poster.setEntity(ent);

HttpResponse responsePost = httpclient.execute(poster);    

但是当我执行此代码时,我遇到了下一个错误:

javax.net.ssl.SSLPeerUnverifiedException: No peer certificate  No peer certificate    

这里有一些类似的问题 没有对等证书。不确定采取哪条路线,但我不想忽略 SSL 证书。 有谁知道它可能是什么?可能是某些服务器错误? (服务器正在开发中,因此可能会出现错误,但在浏览器中它可以与sert一起正常工作)。

I'm developing android application, which connecting to server via https connection.
I've created my_store.bks file with trusted sertificate and using following code to connect to server :

DefaultHttpClient httpclient = new DefaultHttpClient();
KeyStore trustStore  = KeyStore.getInstance("BKS");
InputStream in = context.getResources().openRawResource(R.raw.my_store);
try{ 
  trustStore.load(in,pass.toCharArray());
}
catch(Exception e){
  Log.v("MyLog", "errror reading sert: " + e.toString());
}
finally{
  in.close();
}
SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);


HttpPost poster = new HttpPost(serverAdress);
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(formparams,"UTF-8");
poster.setEntity(ent);

HttpResponse responsePost = httpclient.execute(poster);    

but when I'm executing this code, I've got next error:

javax.net.ssl.SSLPeerUnverifiedException: No peer certificate  No peer certificate    

here is some similar problem
No peer cert. Not sure which route to take but i don't want ignore SSL certificates.
Does anyone know what it may be? May it be some server error? (server is developing, so may have errors, but in browser it works fine with sert).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文