javax.net.ssl.SSLException:连接到Bristol Open Data门户

时间:2016-07-13 23:13:21

标签: socrata soda

我正在尝试使用Apache HttpClient库访问Bristol Open Data门户,但我得到的主机名与证书不匹配。示例代码如下。我无法弄清问题是什么。

DefaultHttpClient client = new DefaultHttpClient();

HttpGet request = new HttpGet("https://opendata.bristol.gov.uk/resource/c2c2-hpww.json");
request.setHeader("X-App-Token","my-token");
HttpResponse response = client.execute(request);

BufferedReader reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent() ) );
String line = reader.readLine();
while (line != null) {
    System.out.println(line);
    line = reader.readLine();
}

此代码生成以下输出:

Exception in thread "main" javax.net.ssl.SSLException: hostname in certificate didn't match: <opendata.bristol.gov.uk> != <*.api.eu.socrata.com> OR <*.api.eu.socrata.com> OR <api.eu.socrata.com>
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:227)
    at org.apache.http.conn.ssl.BrowserCompatHostnameVerifier.verify(BrowserCompatHostnameVerifier.java:54)
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:147)
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
    at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:437)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:643)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
    at RESTTest.main(RESTTest.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

可以在http://pastebin.com/WNFjbSTZ

找到调试输出-Djavax.net.debug=all

0 个答案:

没有答案