restTemplate请求https的ip地址时,会报错:
No subject alternative names matching IP address … found
同样的,在浏览器直接访问浏览器也会提示该地址不安全/证书无效。在高级选项里面可以忽略提示并继续前往。
后端直接请求时,也可以对restTemplate配置ssl安全策略来实现强制信任ssl证书,完整配置如下:
package xxx.common.config;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
impor