0

I have following android POST code. It works fine for http but fails for HTTPS with Not Trusted Server Certificate exception. I do not mind self signing or accepting all certificates code (drawback less secure with man-in-the-middle attack).

 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);

Any help appreciated here. I need the certificate portion of the code with submitting POST with postValue1, postValue2, and postValue3 (minimum 3).

user914425
  • 16,303
  • 4
  • 30
  • 41

1 Answers1

0

You should add the selfsigned certificate to the Android trust store. I've not worked on android self signed cert, but on windows, it will work(mostly)

I've looked up link here. The author gave good steps to install the self signed cert to android.

More discussion here

Community
  • 1
  • 1
Zeus
  • 6,386
  • 6
  • 54
  • 89
  • the issue was my server certificate was expired. I had to renew it and install it again and it worked fine! I was under the impression that renewing is just all I had to do. – user914425 Feb 26 '14 at 15:29