【发布时间】:2017-05-07 08:07:17
【问题描述】:
我已经为此花费了数小时,但无法弄清楚原因。我什至使用了 bls.gov 网站上使用的部分代码示例。我不应该有任何问题,因为它是一个公共 API...请帮助!
public static void main(String[] args) throws ClientProtocolException, IOException {
HttpHost proxy = new HttpHost("myproxy.com", 3128, "http");
CloseableHttpClient httpClient = HttpClientBuilder.create().setProxy(proxy).build(); // Use
// this
// instead
HttpPost request = new HttpPost("https://api.bls.gov/publicAPI/v1/timeseries/data/");
StringEntity params = new StringEntity("{\"seriesid\":[\"LAUCN040010000000005\", \"LAUCN040010000000006\"]}");
request.setEntity(params);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
CloseableHttpResponse response = httpClient.execute(request);
System.out.println("HERE");
System.out.println(response.getStatusLine());
response.close();
不断收到此错误:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
【问题讨论】: