使用Spring WebFlux获取客户端的IP地址
由于我找不到任何代码段这样做,而且很难独自找到这个代码段,所以我必须问社区。我使用REST服务,因此使用此代码:
WebClient
.builder()
.baseUrl(baseUrl)
.build()
.get()
.accept(MediaType.APPLICATION_JSON)
.header(HEADER_NAME_APIKEY, apiKey)
.header(HEADER_NAME_REALM_MANDANT, realmMandant)
.retrieve()
.onStatus(HttpStatus::is4xxClientError, clientResponse -> Mono.just(new RuntimeException(String.format("A client error occured: %s", clientResponse.statusCode()))))
.onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.just(new RuntimeException(String.format("A server error occured: %s", clientResponse.statusCode()))))
.bodyToMono(new ParameterizedTypeReference<List<Message>>() {})
.block()
发送GET请求时,我最终会获得连接超时。在端点另一侧与一个人交谈后,我被告知必须先将IP列入白色,然后才能消耗此服务,因此我现在试图找出客户/我的机器的IP地址,因为我尝试尝试从我本地的机器发送此请求。
由于我们一边也有一个代理,因此我现在不确定我应该在另一侧列出哪个IP。打开CMD并执行IPCONFIG以找到IP似乎对我来说是不合适的。可能是解决代理到IP的主机名。我认为在启动GET请求之前以编程性获得IP是最好的解决方案。所以我在这里,有点毫无意义。
如何使用此WebClient对象获得IP地址?这是我选择的正确方向,还是应该坚持将代理主机名解析为IP?
Since I wasn't able to find any code snippet doing this and also have difficulties finding this on my own I have to ask the community. I consume a REST service and therefore use this code:
WebClient
.builder()
.baseUrl(baseUrl)
.build()
.get()
.accept(MediaType.APPLICATION_JSON)
.header(HEADER_NAME_APIKEY, apiKey)
.header(HEADER_NAME_REALM_MANDANT, realmMandant)
.retrieve()
.onStatus(HttpStatus::is4xxClientError, clientResponse -> Mono.just(new RuntimeException(String.format("A client error occured: %s", clientResponse.statusCode()))))
.onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.just(new RuntimeException(String.format("A server error occured: %s", clientResponse.statusCode()))))
.bodyToMono(new ParameterizedTypeReference<List<Message>>() {})
.block()
When sending a GET request I end up getting a Connection timeout. After talking to a person on the other side of the endpoint I have been told that the IP needs to be whitelisted before I can consume this service so I am now trying to figure out the IP address of a client/my machine since I try to send this request from my local machine.
Since there is also a proxy on our side I am now unsure which IP I should get whitelisted on the other side. Opening cmd and executing ipconfig to find the IP seems not right to me. Possible way would be maybe to resolve the hostname of the proxy to an IP. I thought that obtaining the IP programmatically right before firing the GET request would be the best solution. So here I am, a bit clueless what to do next.
How can I obtain the IP address using this WebClient object? Is it the right direction I picked or should I stick to resolving the proxy hostname to an IP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论