javax.net.ssl.SSLPeerUnverifiedException:java中的peer not authenticated错误

时间:2016-07-26 06:23:07

标签: http-post httpclient

当我尝试在服务器中运行应用程序时,我遇到了以下错误。一些在服务器中工作的API没有问题,只有一个API发出以下错误。

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:390)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)

这是我正在尝试访问API的代码。

HttpClient client = new DefaultHttpClient();

        HttpPost post = new HttpPost(
                "https://mife.smobile.lk/apicall/dialogloanprepaid/v1.0/auto");

        JSONObject json = new JSONObject();
        StringEntity params = new StringEntity("{\"msisdn\":\"" + mobile
                + "\",\"channel\":\"IVR\"}");

        new StringEntity(json.toString());
        post.addHeader("content-type", "application/json");
        post.addHeader("Authorization", "Bearer " + access_token);
        post.addHeader("Accept", "application/json");

        post.setEntity(params);
        HttpResponse response = client.execute(post);
        int status = response.getStatusLine().getStatusCode();
        System.out.println("status code is :" + status);
        resCode = Integer.toString(status);

        BufferedReader rd = new BufferedReader(new InputStreamReader(
                response.getEntity().getContent()));
        String response1 = readAll(rd);
        System.out.println(response1);
        JSONObject obj = new JSONObject(response1);
        resCode = obj.getString("resCode");
        resDesc = obj.getString("resDesc");

是否可以从代码级别完成任务以解决问题。请帮忙。

0 个答案:

没有答案