获取错误javax.net.ssl.SSLException

时间:2016-04-07 09:13:24

标签: android

从android应用程序调用api时遇到问题。当我从浏览器调用它时,Api不会产生任何问题。我在下面发布我的代码和我得到的回复。

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

我得到的错误是javax.net.ssl.SSLException

1 个答案:

答案 0 :(得分:0)

  

这是由于连接   与客户机建立的是   不安全。

这是因为您正在与HTTP服务器通信,而不是HTTPS服务器。可能您没有使用正确的HTTPS端口号。