首页 > IT职业 > IT图书 > 如何通过httpclient获取访问域名的真实ip
需求:由于目标网站cdn节点很多需要获取到访问当次是哪个ip。
1、实现接口HttpConnectionManager新加实现类A,直接复制SimpleHttpConnectionManager的类内容。
2、A类增加方法
public Socket getSocket() {
return this.httpConnection.getSocket();
}
3、为httpClient指定HttpConnectionManager
方法为 httpClient 指定httpClient.setHttpConnectionManager(new A());
4、httpClient.executeMethod执行后获取httpClient.getHttpConnectionManager(),强制转换为A.
5、通过getSocket().getInetAddress().getHostAddress()可以获取到当次请求真实ip.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1075/viewspace-2813844/ ,如需转载,请注明出处,否则将追究法律责任。