我正在从控制器中调用POST端点。 POST端点验证用户并返回cookie。我是Spring Web-flux的新手,所以需要获取cookie并将其发送回去。
@PostMapping(value = "/valid")
public ResponseWrapper<UserResponseDTO> validate(
@RequestBody @Valid RequestWrapper<UserRequestDTO> request,
HttpServletResponse res) {
WebClient webClient = WebClient.builder()
.baseUrl(BASE_URI)
.defaultHeader(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE)
.build();
Mono<ResponseWrapper> response = webClient.post()
.uri(PWD_AUTH_URI)
.contentType(MediaType.APPLICATION_JSON)
.syncBody(request)
.retrieve()
.bodyToMono(ResponseWrapper.class);
ResponseWrapper<UserResponseDTO> wr = response.block();
// how to get cookie from the webClient
// set into the "res" that cookie
return wr;
}