进行SSL连接时出错

时间:2016-11-14 09:28:09

标签: android ssl android-networking

我正在使用以下代码进行服务器连接

    HttpResponse response = null;
    // Creating HTTP client
    HttpClient httpClient = new DefaultHttpClient();
    // Creating HTTP Post
    HttpEntity entity = null;
    String data = null;
    // Making HTTP Request
    try {
        if (method == KEY_GET) {
            HttpGet httpget = new HttpGet(url);
            response = httpClient.execute(httpget);
        } else if (method == KEY_POST) {
            HttpPost httpPost = new HttpPost(url);
            httpPost.addHeader("Content-Type", "application/json;    charset=utf8");
            httpPost.addHeader("Accept", "application/json");
            //convert parameters into JSON object
            StringEntity se = null;
            //passes the results to a string builder/entity
            try {
                se = new StringEntity(postParameter.toString());
            } catch (Exception e) {

            }
            //sets the post request as the resulting string
            httpPost.setEntity(se);
            response = httpClient.execute(httpPost);
        }
        entity = response.getEntity();
        data = EntityUtils.toString(entity);
    } catch (ClientProtocolException e) {
        // writing exception to log
        e.printStackTrace();
    } catch (IOException e) {
        // writing exception to log
        e.printStackTrace();

    } catch (Exception e2) {
        e2.printStackTrace();
    }

早些时候,它适用于所有请求。但现在在服务器上实现SSL后,它给了我“javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。”错误。

我该如何解决?

提前致谢

0 个答案:

没有答案