0

I am facing a problem while calling api from android application . Api create no problems when i call them from browser . I am posting my code below and the response i got.

    HttpResponse httpresponse=null;

    try {
        HttpClient client = new DefaultHttpClient();
        HttpClient httpclient2 = new DefaultHttpClient();
        HttpEntity entity=null;                                 
        HttpPost post=new HttpPost(url);
        post.setEntity(new UrlEncodedFormEntity(parList,"UTF-8"));
        httpresponse= client.execute(post);
        entity=httpresponse.getEntity();
        response=EntityUtils.toString(entity);

        Log.d("code of response", ""+httpresponse.getStatusLine().getStatusCode());

        if(httpresponse.getStatusLine().getStatusCode()==200){
            if (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {


                Log.d("code", ""+httpresponse.getStatusLine().getStatusCode());

                Header authHeader = httpresponse.getFirstHeader(AUTH.WWW_AUTH);
                DigestScheme digestScheme = new DigestScheme();

                //Parse realm, nonce sent by server. 
                digestScheme.processChallenge(authHeader);

                UsernamePasswordCredentials creds = new UsernamePasswordCredentials("cuztomise", "123456");
                post.addHeader(digestScheme.authenticate(creds, post));

                ResponseHandler<String> responseHandler = new BasicResponseHandler();
                String responseBody = httpclient2.execute(post, responseHandler);
                return responseBody;
            }
            return response;
            }else{

                makelogs(url, "", parList.toString(),""+httpresponse.getStatusLine().getStatusCode(),context_new,response);
                return response;
            }
    } catch (IOException | MalformedChallengeException | AuthenticationException e) {
        // TODO Auto-generated catch block

        makelogs(url, e.toString(), parList.toString(),""+httpresponse.getStatusLine().getStatusCode(),context_new,response);
        e.printStackTrace();
        return e.toString();
    }catch (Exception e) {
        // TODO: handle exception
        makelogs(url, e.toString(), parList.toString(),""+httpresponse.getStatusLine().getStatusCode(),context_new,response);
        e.printStackTrace();
        return e.toString();
    }

Error i got is javax.net.ssl.SSLException

sanjay
  • 228
  • 2
  • 12
  • May this help you http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https – mubeen Apr 07 '16 at 09:22

1 Answers1

0

this is due to the connection established with the client machine is not secure.

It is due to the fact that you are talking to an HTTP server, not an HTTPS server. Probably you didn't use the correct port number for HTTPS.