OpenFeign调用包含Cookie的接口
@Headers("Cookie: {cookie}")
@PostMapping("/xxxx/login")
Object login(@RequestHeader("Cookie") String cookie, @RequestBody LoginDTO dto);
这个cookie怎么获取呢?在RequestHeader中可以看到
在代码中获取
ResponseEntity<byte[]> response = restTemplate.getForEntity(url, byte[].class);
// 获取响应头
HttpHeaders responseHeaders = response.getHeaders();
// 获取响应头中的Cookie
List<String> cookies = responseHeaders.get(HttpHeaders.SET_COOKIE);
// 打印Cookie内容
if (cookies == null) {
log.error("获取Cookie失败");
return ResponseEntity.status(500).body(null);
} else {
iconCookie = cookies.get(0);
log.info(iconCookie);
}