我正在尝试实施Google Analytics(分析)之类的服务。嵌入在不同应用程序中的客户端JS将调用此服务。
在我的服务中,我想提取呼叫者应用程序的URL。有什么方法可以在我的服务中提取此信息,而不是让客户端JS发送信息(出于数据安全性的考虑,客户端不太可取)?
答案 0 :(得分:1)
为此在 API 参数中添加 HttpServletRequest 请求并尝试这个
String uri = request.getScheme() + "://" + // "http" + "://
request.getServerName() + // "localhost"
":" + request.getServerPort() + // ":" + "8080"
request.getRequestURI() + // "/employee"
(request.getQueryString() != null ? "?" +
request.getQueryString() : ""); // "?" + "lastname=Kumar&age=30"