Android HTTPS POST给出错误不可信服务器证书

时间:2014-02-20 22:02:28

标签: android https http-post ssl-certificate

我有以下android POST代码。它适用于http,但对于具有不可信服务器证书异常的HTTPS失败。我不介意自我签名或接受所有证书代码(中间人攻击的安全性较差)。

 HttpPost post = new HttpPost("https://yourdomain.com/yourskript.xyz");
 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

 nameValuePairs.add(new BasicNameValuePair("postValue1", "my Value"));
 nameValuePairs.add(new BasicNameValuePair("postValue2", "2nd Value"));
 nameValuePairs.add(new BasicNameValuePair("postValue3", "3rd Value"));
 post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

 HttpClient client = new DefaultHttpClient(); HttpResponse response =
 client.execute(post); HttpEntity entity = response.getEntity();

 String responseText = EntityUtils.toString(entity);

这里有任何帮助。我需要使用postValue1,postValue2和postValue3(最少3)提交POST的代码的证书部分。

1 个答案:

答案 0 :(得分:0)

您应该将自签名证书添加到Android信任库。我没有使用android自签名证书,但在Windows上,它可以工作(主要是)

我查找了链接here。作者给出了安装自签名证书到android的好步骤。

更多讨论here