【发布时间】:2012-05-26 03:56:42
【问题描述】:
我正在做一个项目,我的同事在该项目中实现了一个使用自签名服务器的 https 服务器,并且我正在设计一个向其发送 httpposts 的 Android 应用程序。他已经使用 curl 对其进行了测试,没有任何问题。如果相关,我使用的是 Android 3.2。
按照本教程here,我生成了一个密钥库并将其添加到应用程序中,同时还创建了一个自定义 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
你能告诉我这与什么有关吗?谢谢。
【问题讨论】:
标签: android https certificate