如何在我的REST服务中获取调用应用程序的URL?

时间:2019-05-19 20:23:51

标签: javascript node.js http networking

我正在尝试实施Google Analytics(分析)之类的服务。嵌入在不同应用程序中的客户端JS将调用此服务。

在我的服务中,我想提取呼叫者应用程序的URL。有什么方法可以在我的服务中提取此信息,而不是让客户端JS发送信息(出于数据安全性的考虑,客户端不太可取)?

1 个答案:

答案 0 :(得分:1)

我想你想要这样的东西: URL of the caller

为此在 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"