如何从Google Cloud端点获取远程IP地址?

时间:2019-10-05 11:40:52

标签: java google-cloud-endpoints

我正在尝试检查调用者是否针对Google Cloud Endpoint中的方法 白名单。如何获取客户端的远程地址? (以及如何获取请求对象?)

更新:感谢@ikerlasaga:

@ApiMethod(name = "echo")
public Message echo(HttpServletRequest req, Message message, @Named("n") @Nullable Integer n) {

  String remote = req.getRemoteAddr();

  return doEcho(message, n);
}

1 个答案:

答案 0 :(得分:1)

来自此帖子:Getting raw HTTP Data (Headers, Cookies, etc) in Google Cloud Endpoints

@ApiMethod(name = "echo")
public Message echo(HttpServletRequest req, Message message, @Named("n") @Nullable Integer n) {

  String remote = req.getRemoteAddr();

  return doEcho(message, n);
}

感谢@ikerlasaga