简体   繁体   English

我可以使用Apache HttpClient获取响应服务器名称/ ip吗?

[英]Can I get the response server name/ip using Apache HttpClient?

I'm using Apache HttpClient 3.x for contacting a Big IP that will then redirect my request to one of 1-N machines. 我正在使用Apache HttpClient 3.x与Big IP联系,然后将我的请求重定向到1-N机器之一。 We have the need to know which of the N machines actually picked up the request though, and I'm not sure how to get this information. 但是,我们需要知道N台机器中的哪台实际接收了请求,我不确定如何获取此信息。 I looked through the Response headers with no luck, so I'm wondering if this information is actually provided anywhere? 我运气不佳地浏览了Response标头,所以我想知道此信息是否真的在任何地方提供? Is there a helper/utility class I can use to get any additional metadata? 我可以使用帮助程序/实用程序类来获取任何其他元数据吗?

Thanks. 谢谢。

If the request is redirected and you need the new location, you need to setFollowRedirects(false) on the method and handle the redirect yourself. 如果请求被重定向并且您需要新的位置,则需要在方法上设置setFollowRedirects(false)setFollowRedirects(false)处理重定向。

After sending the request, check getStatusCode() for 302 and getResponseHeader("Location") for the new address. 发送请求后,检查getStatusCode()302getResponseHeader("Location")的新地址。 Than change the address by setURI() and send again. 比通过setURI()更改地址并再次发送。

或者,您可以只使用mod_headers并在每台Apache httpd服务器上插入唯一的Header ID ;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM