Apache HttpClient 日志目标 IP 地址

时间:2021-03-09 13:13:04

标签: java apache-httpclient-4.x

我需要记录 Apache HttpClient 调用的目标 IP 地址。所以要调用的代码是这样的:

public void setForDepartment(String department) {

    String url = urlProps.get(department);
    HttpGet get = new HttpGet(url);
    HttpResponse response = getHttpsClient().execute(get);

}

public CloseableHttpClient getHttpsClient() {

   /* code to create the Http Client */
}

记录 URL 非常容易,因为它已传递到方法中。但是要求很明确,需要记录的IP地址。

如何强制查找远程 IP 地址以进行日志记录?如果这使用了“标准”servlet 类,例如 HttpServletRequestHttpServletResponse`, it would be easy to call the getRemoteAddr()method. That method is not available on theHttpResponse`` 类。

谁能告诉我我将如何执行查找以便我可以记录它? HttpClient 版本是 apache-httpcomponents 4.5.5 的一部分。

0 个答案:

没有答案
相关问题