I used to call HttpServletRequest.getRemoteAddr() to get client ip.
I'm wondering how can I get it via ServerWebExchange.
My best guess is:
serverWebExchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
Is it correct?
you can use org.springframework.http.server.reactive.ServerHttpRequest
,
String remoteAddress = serverHttpRequest.getRemoteAddress().getAddress().getHostAddress();
as it sad in doc: .reactive.ServerHttpRequest
represents a reactive server-side HTTP request.
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/server/reactive/ServerHttpRequest.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With