我们可以在网址中为本地主机添加https吗

时间:2018-09-24 12:28:29

标签: java

我想使用HttpClient与本地主机执行HTTPS URL。请找到以下代码。当我运行以下代码时,它抛出异常。它询问有效的证书路径。但是我不知道如何获得有效的证书。请帮助我摆脱这个问题。

private void test() throws Exception {

    String url = "https://localhost:8080/Example/Rest/Test";

    SystemDefaultRoutePlanner routePlanner = new SystemDefaultRoutePlanner(
            ProxySelector.getDefault());
    HttpClient httpclient = HttpClients.custom()
            .setRoutePlanner(routePlanner).build();

    HttpGet post = new HttpGet(url);
    try {
        HttpResponse response = httpclient.execute(post);

        System.out.println(response.getStatusLine().getStatusCode());
    } catch (ValidationException e) {
        System.out.println(e.getMessage());
    }
    System.out.println("final");

}

0 个答案:

没有答案