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.
本文转自 cd1989929 51CTO博客,原文链接:http://blog.51cto.com/chend/2068906