0

I try to send https Get Request.i wrote some code to send request but i have SSLPeerUnverifiedException: No peer certificate.this is a my source

public void SendHttpGetRequest(final String mykey, final String mydt) {

    class CheckLattery extends AsyncTask<String, Void, String> {
        ProgressDialog pDialog;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            pDialog = new ProgressDialog(MainActivity.this);

            pDialog.setCancelable(false);
            pDialog.show();
            pDialog.setContentView(R.layout.custom_progressdialog);
        }
        @Override
        protected String doInBackground(String... params) {

            HttpClient httpClient = createHttpClient();
            try {

                HttpGet httpGet = new HttpGet(
                        "https://**********/api/");
                httpGet.setHeader("key", mykey);

                httpGet.setHeader("dt", mydt);
                HttpResponse httpResponse = httpClient.execute(httpGet);

                System.out.println("httpResponse");
                InputStream inputStream = httpResponse.getEntity()
                        .getContent();
                InputStreamReader inputStreamReader = new InputStreamReader(
                        inputStream);
                BufferedReader bufferedReader = new BufferedReader(
                        inputStreamReader);
                StringBuilder stringBuilder = new StringBuilder();

                String bufferedStrChunk = null;
                while ((bufferedStrChunk = bufferedReader.readLine()) != null) {
                    stringBuilder.append(bufferedStrChunk);
                }
                System.out.println("Returning value of doInBackground :"
                        + stringBuilder.toString());
                return stringBuilder.toString();

            } catch (ClientProtocolException cpe) {
                System.out
                        .println("Exception generates caz of httpResponse :"
                                + cpe);
                cpe.printStackTrace();
            } catch (IOException ioe) {
                System.out
                        .println("Second exception generates caz of httpResponse :"
                                + ioe);
                ioe.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if (pDialog != null) {
                pDialog.dismiss();
                pDialog = null;
            }

            Log.wtf("result", result+"res");

        }
    }
    CheckLattery latterychek = new CheckLattery();
    latterychek.execute();
}




public static HttpClient createHttpClient() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,
            HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory
            .getSocketFactory(), 80));
    schReg.register(new Scheme("https",
            SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(
            params, schReg);

    return new DefaultHttpClient(conMgr, params);
}

i searched and i found some examples but i can't solve my problem.I have no idea what is a wrong in my code. if anyone knows solution please help me thanks

jww
  • 97,681
  • 90
  • 411
  • 885
lucka
  • 13
  • 1
  • 5
  • Are you using self signed certificate? If yes, check this question http://stackoverflow.com/questions/1217141/self-signed-ssl-acceptance-android – rstk Dec 23 '14 at 21:12
  • @rstk no sir.i never had this error and i don't know how to use ssl veripication – lucka Dec 23 '14 at 21:27

0 Answers0