【发布时间】:2011-04-18 08:46:22
【问题描述】:
我正在通过 https 从我的 android 客户端调用 Web 服务。我必须验证从服务器端接收的证书。我怎么做 ?目前,这是我用来调用 Web 服务的代码。
private static String SendPost(String url, ArrayList<NameValuePair> pairs) { // url = "https://....."
errorMessage = "";
String response = "";
DefaultHttpClient hc=new DefaultHttpClient();
ResponseHandler <String> res=new BasicResponseHandler();
HttpPost postMethod=new HttpPost(url);
try {
postMethod.setEntity(new UrlEncodedFormEntity(pairs));
response = hc.execute(postMethod, res);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
如何验证在执行 Post 期间从服务器收到的自签名证书?我必须通过公钥/私钥进行测试。客户端将有一个 CA 文件。我只需要客户端使用 CA 验证服务器证书,服务是公共的。这与公钥/私钥有关。在调用帖子之前如何从服务器接收证书?
它们是 stackoverflow 上提供的几个选项和代码 sn-ps。我发现有多个答案的几个链接是: Accepting a certificate for HTTPs on Android HTTPS GET (SSL) with Android and self-signed server certificate
但我不知道哪个对我好/适用!我不想禁用所有或接受任何。必须检查公钥/私钥/
非常感谢任何帮助。
【问题讨论】:
标签: android web-services ssl certificate