Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending JSON params with HTTPS request

Tags:

android

https

I need to call "HTTPS" api and pass JSON params with it to the server.
Right now i am trying like this:

HttpClient httpclient = new DefaultHttpClient();

            HttpPost httppost = new HttpPost("https://myapi call goes here...");
            httppost.setHeader("Content-Type", "application/json");

            try
            {

                JSONObject j = new JSONObject();
                j.put("email", "my email value goes here");

                StringEntity s = new StringEntity(j.toString());

                httppost.setEntity(s);
                HttpResponse response = httpclient.execute(httppost);

                /* Checking response */
                if(response != null)
                {
                    responseBody = EntityUtils.toString(response.getEntity());


                }
                if(responseBody.equals("ok"))
                {



                }
            }
            catch (final Exception e)
            {
                e.printStackTrace();


            }  

But its gives me exception: SSL Peer unverified: No Peer Certificate.
Please note that i have to use only HTTPS for making call to api.

Anybody any idea??

like image 886
Noman Avatar asked Nov 02 '22 15:11

Noman


1 Answers

Take a look at this answer. It is well explained and is probably what you need to correct your code.

like image 80
Dyna Avatar answered Nov 09 '22 15:11

Dyna