webclientbuilder.baseUrl(url)
.defaultHeaders(headers -> headers.addAll(requestHeader))
.build()
.post()
.uri("/uri")
.bodyValue(data)
.exchange()
.flatMap(response -> {
if(response.statusCode() == HttpStatus.UNAUTHORIZED){
//retry with updated token in header
}
})
//return bodyToMono of specific object when retry is done or if
//response status is 2xx
Run Code Online (Sandbox Code Playgroud)
任何有关如何处理此问题的建议将不胜感激!正如评论所说,如果 statusCode 为 UNAUTHORIZED,并且如果 statusCode 为 2xx,则在重试 post 请求之前,我需要将新令牌添加到标头,然后返回 bodyToMono。
spring request-headers spring-retry spring-boot spring-webclient