JAVA - No subject alternative names matching IP address

北战南征 提交于 2019-12-25 01:48:32

问题


I am trying to use get request on site with REST API. However the link to acces it is an IP address and I am getting the No subject alternative names matching IP address error.

When I use the same exact link in browser, it works.

How can I solve this issue?

Below is my code:

public static void main(String[] args) {

    System.getProperties().put( "proxySet", "true" );
    System.getProperties().put( "socksProxyHost", "xxx.xxx.xxx.xxx" );
    System.getProperties().put( "socksProxyPort", "xxxx" );


    URL requestLink = ismTicketManager.UrlEncode.convertToURLEscapingIllegalCharacters("https://xx.xx.xx.xx/e/528f5016-6fd9-403f-85e4-5a54bb2498b9/api/v1/problem/feed?relativeTime=30mins&Api-Token=xxxxx");

    try {
        HttpURLConnection targetConn = (HttpURLConnection)requestLink.openConnection();
        targetConn.setRequestMethod("GET");
        System.out.println(targetConn.getResponseCode());
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Connection failed");
    }

    static {
    HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> hostname.equals("127.0.0.1"));
}

}

Now I am getting error:

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

The cacerts fiel list looks like this:

restapi, 25-Sep-2018, trustedCertEntry, Certificate fingerprint (SHA1): AB:6D:C6:2E:9F:B3:D9:48:1E:A9:84:AA:DD:03:64:1D:7C:08:42:CE

Thank you for your time.

来源:https://stackoverflow.com/questions/52496137/java-no-subject-alternative-names-matching-ip-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!