2014-02-20 55 views
0

我有以下的Android POST代码。它可以正常工作,但对于不可信服务器证书异常的HTTPS会失败。我不介意自签名或接受所有的证书代码(中间人攻击不太安全)。Android HTTPS POST给出错误不可信服务器证书

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代码的证书部分。

回答

0

您应该将自签名证书添加到Android信任存储区。我没有在Android自签名证书工作,但在Windows上,它将工作(主要)

我抬头链接here。作者提供了很好的步骤来将自签名证书安装到android。

更多讨论here

+0

的问题是我的服务器证书过期。我不得不续约它,并再次安装它,它工作正常!我的印象是更新只是我所要做的。 – user914425

相关问题