resttemplate访问ip地址受阻,但可访问域名
问题描述:
resttemplate无法访问内网ip地址加上端口号的地址,而是报错404,而通过域名访问时却可以正常连接。
解决方法:
通过重写httpurlconnection的headers属性host,可以解决此问题:
System.setProperty("sun.net.http.allowRestrictedHeaders", "
true");通过设置该属性,可以覆盖自定义添加的host,使其生效。
resttemplate访问ip地址受阻,但可访问域名
问题描述:
resttemplate无法访问内网ip地址加上端口号的地址,而是报错404,而通过域名访问时却可以正常连接。
解决方法:
通过重写httpurlconnection的headers属性host,可以解决此问题:
System.setProperty("sun.net.http.allowRestrictedHeaders", "
true");通过设置该属性,可以覆盖自定义添加的host,使其生效。