我正在使用Aapache httpclient代码来读取具有摘要式身份验证的URL . 我遇到了安全违规行为 . 此网址/用户名/密码在浏览器中正常运行 . 怎么了?

public static void main(String[] args) throws Exception {

    String url = "https://httpbin.org/digest-auth/auth/user/passwd";
    String username = "user";
    String password = "passwd";

    CookieStore cookieStore = new BasicCookieStore();
    BasicClientCookie cookie = new BasicClientCookie("fake", "fake_value");
    cookie.setDomain("httpbin.org");
    cookie.setPath("/");
    cookieStore.addCookie(cookie);


    // get the host
    HttpHost httpHost = URIUtils.extractHost(new URI(url));

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(httpHost.getHostName(), httpHost.getPort()), new UsernamePasswordCredentials(username, password));

    CloseableHttpClient httpClient = HttpClients.custom()
            .setDefaultCookieStore(cookieStore)
            .setDefaultCredentialsProvider(credsProvider)
            .setRedirectStrategy(new LaxRedirectStrategy())
            .build();

    // Create AuthCache instance
    // Generate BASIC scheme object and add it to the local auth cache
    AuthCache authCache = new BasicAuthCache();
    DigestScheme digestAuth = new DigestScheme();
    digestAuth.overrideParamter("realm", "support@windward.net");
    digestAuth.overrideParamter("nonce", calculateNonce());
    authCache.put(httpHost, digestAuth);

    // Add AuthCache to the execution context
    HttpClientContext localContext = HttpClientContext.create();
    localContext.setAuthCache(authCache);


    CloseableHttpResponse response = null;
    HttpGet httpGet = new HttpGet(url);
    response = httpClient.execute(httpHost, httpGet, localContext);
    if (response.getStatusLine().getStatusCode() != 200)
        throw new IOException("Error: " + response.getStatusLine() + ". Reading url " + url);
    HttpEntity entity = response.getEntity();
    InputStream stream = entity.getContent();
}

private static synchronized String calculateNonce() {

    Date d = new Date();
    SimpleDateFormat f = new SimpleDateFormat("yyyy:MM:dd:hh:mm:ss");
    String fmtDate = f.format(d);
    Random rand = new Random(100000);
    Integer randomInt = rand.nextInt();
    return org.apache.commons.codec.digest.DigestUtils.md5Hex(fmtDate + randomInt.toString());
}

例外:

线程“main”中的异常javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法在sun处找到所请求目标的有效证书路径 . security.ssl.Alerts.getSSLException(Alerts.java:192)at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1904)at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:279)at sun .security.ssl.Handshaker.fatalSE(Handshaker.java:273)在sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1446)在sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:209)在sun.security.ssl.Handshaker.processLoop(Handshaker.java:901)at sun.security.ssl.Handshaker.process_record(Handshaker.java:837)at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1023) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)at sun.security.ssl.SSLSocketImpl.startHandshake(SSLS) ocketImpl.java:1359)在sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)在org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)在org.apache.http .conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect (PoolingHttpClientConnectionManager.java:353)在org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)在org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)在org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)org.apache.http.impl . execchain.RedirectExec.execute(RedirectExec.java:110)at org.apache.http.impl.client.InternalHttpClient.doE xecute(InternalHttpClient.java:184)在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)在net.windward.util.AccessProviders.SampleDigestRequest.main(SampleDigestRequest.java:82)引起的:sun.security.validator.ValidatorException:PKIX路径建设失败:sun.security.provider.certpath.SunCertPathBuilderException:无法在sun.security.validator.PKIXValidator.doBuild找到有效的认证路径要求的目标(PKIXValidator.java:385) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)与目标虚拟机断开连接,地址:'127.0.0.1:59052',传输:'socket'at sun.security.validator.Validator.validate(Validator)的.java:260)在sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)在sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)在sun.security.ssl.X509TrustManagerImpl.checkServerTrusted( X509TrustManagerImpl.java:126)在sun.security.ssl.ClientHand shaker.serverCertificate(ClientHandshaker.java:1428)... 19更多引起:sun.security.provider.certpath.SunCertPathBuilderException:无法在sun.security.provider.certpath.SunCertPathBuilder.engineBuild找到所请求目标的有效证书路径( SunCertPathBuilder.java:196)at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)... 25更多