由于目前的项目中有如下场景:RestTemplate 发送Get请求到一ip,并要求请求头中带上跳转的Host,几经测试,未能走通,一直报的是403错误;而直接通过Postman 发送是没问题的。
RestTemplate template = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.HOST,"www.xxx某个网站域名.com");
ResponseEntity<String> response = template.exchange(
"http://请求的ip地址",
HttpMethod.GET,
new HttpEntity<String>(headers),
String.class);
System.out.println(response);
问题截图如下:
当时就觉得见鬼了,于是就通过WireShark抓请求包,比较发现,发送出去的请求headers里带的Host不一致,