1

In my Android application I use http link for get JSON response from server, now they changed to https. My code is return No peer certificate exception.

What the things need to get response from server using https in Android. This is the code I used for get response from server for http.

public static DefaultHttpClient httpClient;
public static ResponseHandler<String> resHandler;
public static List<NameValuePair> nameValuePairs;
public static HttpPost httpPost;

     ....

httpClient = new DefaultHttpClient();
resHandler = new BasicResponseHandler();
httpPost = new HttpPost("https://www.xxx.com/.../user/renting");
nameValuePairs = new ArrayList<NameValuePair>(6);

nameValuePairs.add(new BasicNameValuePair("parking_spot_id".trim(),
        spotID));
    ....
for (int i = 0; i < array.length; i++) {
    nameValuePairs.add(new BasicNameValuePair("date[]", array[i]));
}

try {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    jsonResponse = httpClient.execute(httpPost, resHandler);
    Log.e("rent by day", jsonResponse);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

The above code working well for using http.

1) What are the things I need to get for https.

2) What are the changes in the code.

Please help me.

M.A.Murali
  • 9,988
  • 36
  • 105
  • 182
  • Use this code: http://nelenkov.blogspot.de/2011/12/using-custom-certificate-trust-store-on.html – Robert Apr 08 '14 at 09:56
  • @Robert, I have confused in this concept. please tell me step by step approach to solve. please help me. – M.A.Murali Apr 08 '14 at 10:54
  • Read the section "Using your own trust store: HttpClient" it shows you the code you have to use. The problem is that the https server uses a certificate that is not trusted by your Android platform. Therefore you have to manually add it into your app. – Robert Apr 08 '14 at 11:24
  • I think this [answer][1] may help you [1]: http://stackoverflow.com/questions/9531710/problems-with-https-no-peer-certificate-in-android?lq=1 – Dania Delbani Apr 25 '15 at 17:59

0 Answers0