0

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.

GohanCZ
  • 13
  • 7
  • https://stackoverflow.com/questions/10258101/sslhandshakeexception-no-subject-alternative-names-present – Malt Sep 25 '18 at 10:39
  • @Malt Thank you for the link, looking at static { HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> hostname.equals("127.0.0.1")); } Where would I put this in my code? – GohanCZ Sep 25 '18 at 10:46
  • Actually I put the code into my class, now I am getting: 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 – GohanCZ Sep 25 '18 at 10:51

0 Answers0