Apache HttpClient - POST到https url安全吗?

时间:2016-02-04 10:06:14

标签: java apache ssl apache-httpclient-4.x

我想要执行HTTP POST请求,该请求由ssl保护。

客户端是我的java程序,它发布到https-url(https:// ...)。验证了网站的证书,我正在使用Apache HttpClient 4.5.1 使用正常的post-request和自定义httpclient。

    HttpContext context = HttpClientContext.create();
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE);
    cm.setMaxTotal(MAX_TOTAL_CONNECTIONS);
    CloseableHttpClient client = HttpClients.custom()
            .setConnectionManager(cm)
            .build();
    HttpContext context = HttpClientContext.create();

    HttpPost login = new HttpPost("https://example.org"); // example url
    login.addHeader("Content-Type", "application/json; charset=UTF-8");
    login.addHeader("Accept", "application/json; charset=UTF-
    login.setEntity(new StringEntity(loginData, ContentType.create("application/json", "UTF-8")));

    JSONResponseHandler<JSONObject> rh = new JSONResponseHandler<>();
    JSONObject test = client.execute(login, rh, context);

这是否足以获得ssl安全连接或我是否必须使用KeyStoreSSLContextSSLConnectionFactory

如果我必须使用它们,我将如何以高效的方式做到这一点。我只看到了如何允许自签名证书的示例。

0 个答案:

没有答案