gpt4 book ai didi

java - 如何在 ContainerRequestFilter 中获取远程 IP

转载 作者:行者123 更新时间:2023-11-30 23:45:18 24 4
gpt4 key购买 nike

我有这门课,想记录休息请求:

public class RequestFilter implements ContainerRequestFilter {

private static final Logger LOG = LoggerFactory.getLogger(RequestFilter.class);

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
LOG.info("REST-Request from '{}' for '{}'", "XXX", requestContext.getUriInfo().getPath());
// ... and do some auth stuff (not relevant for this question)
}
}

如何获取请求的远程 IP?蒂亚!

最佳答案

尝试这个:

public class RequestFilter implements ContainerRequestFilter {

private static final Logger LOG = LoggerFactory.getLogger(RequestFilter.class);

@Context
private HttpServletRequest request;

// rest of your stuff here

关于java - 如何在 ContainerRequestFilter 中获取远程 IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24724190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com