我正在一个项目中,我的同事实现了一个 https 服务器,它使用一个自签名服务器,我正在设计一个向它发送 httpposts 的 android 应用程序。他使用 curl 对其进行了测试,没有任何问题。如果相关,我正在使用 Android 3.2。
按照此处的本教程,我生成了一个密钥库并将其添加到应用程序中,同时还创建了一个自定义 httpClient。我使用以下代码将 get 请求替换为 post:
private InputStream postHttpConnection(String urlValue,
JSONObject jsonPost, Context context) {
InputStream inStream = null;
URL url;
try {
url = new URL(urlValue);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
Log.e("postHttpConnection", "Fail: " + "Not an HTTP connection");
} catch (MalformedURLException e) {
Log.e("postHttpConnection", "Fail: " + e);
} catch (IOException e) {
Log.e("postHttpConnection", "Fail: " + e);
}
try {
DefaultHttpClient client = new MyHttpClient(context);
HttpConnectionParams
.setConnectionTimeout(client.getParams(), 10000);
HttpResponse postResponse;
HttpPost post = new HttpPost(urlValue);
StringEntity se = new StringEntity(jsonPost.toString());
post.setEntity(se);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
postResponse = client.execute(post);
inStream = postResponse.getEntity().getContent();
} catch (ClientProtocolException e) {
Log.e("postHttpConnection", "Fail: " + e);
} catch (IOException e) {
Log.e("postHttpConnection", "Fail: " + e);
}
return inStream;
}
当我通过适当的 JSONObject 使用此函数时,我收到以下错误:
E/postHttpConnection(9236): Fail: javax.net.ssl.SSLException: Certificate for <address> doesn't contain CN or DNS subjectAlt
你能告诉我这与什么有关吗?谢谢你。