java calling ip to directly access https interface problem


@Test
	public void initData() {
		BufferedReader reader = null;
		InputStream is = null;
		try {
			URL url = new URL("https://xxx.xxx.xxx.xxx/api/xxx");
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.setRequestMethod("GET");
			connection.setRequestProperty("Content-Type", "application/xml;charset=utf-8;");
			connection.setRequestProperty("Authorization", "Basic xxxxxxxxxxxxxxxxxxxxxxxxx=");
			connection.connect();
			is = connection.getInputStream();
			reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
			StringBuilder buffer = new StringBuilder();
			String strRead = null;
			while ((strRead = reader.readLine()) != null) {
				buffer.append(strRead);
			}
			System.out.println(buffer);
		} catch (Exception e) {
			e.printStackTrace ();
		} finally {
			IOUtils.closeQuietly(reader);
			IOUtils.closeQuietly(is);
		}

	}






The error is as follows
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)


The result of online search is that ip access is not supported, it must be Use the domain name


and then modify the hosts for local resolution
192.168.1.153 www.test.com
nginx domain name jump
server {
        listen 80;
        server_name www.test.com;
        location / {
    proxy_pass https://xxx.xxx.xxx.xxx;

}
}
you're done

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326800229&siteId=291194637