如何获取REST消费者的IP地址 [英] How to get IP Address of REST Consumer
问题描述
我会尝试用图表来解释
[REST SERVER] <--------> [JAVASCRIPT BASED WEBSITE] <--------> [USER]
192.168.0.2 192.168.0.3 192.168.0.123
如何获取使用 REST 服务器的网站的 IP 而不是 USER 的 IP.
How can I get the IP of the website that consumes the REST server instead of the USER's IP.
我尝试使用 $_SERVER['REMOTE_ADDR'] 和 $_SERVER['HTTP_REFERRER'] 但它们都返回用户的 IP.
I tried using $_SERVER['REMOTE_ADDR'] and $_SERVER['HTTP_REFERRER'] but they both return the IP of the user.
在网络上可以吗?我的 REST 服务器使用 PHP.
Is it possible in the web? I'm using PHP for my REST server.
推荐答案
这里我假设您的意思是该网站托管在 192.168.0.3
上.这意味着用户将从所述服务器下载Javascript和HTML数据,然后在192.168.0.123
上本地执行.然后,该 Javascript 将从该本地 IP 远程调用 REST 服务.
I'll assume here that you mean the website is hosted on 192.168.0.3
. This means the user will be downloading the Javascript and HTML data from said server, and then execute it locally on 192.168.0.123
. That Javascript is then going to make remote calls to the REST service from that local IP.
您想知道如何在客户端下载之前获取托管 Javascript/HTML 文件的服务器的 IP,大概是以一种可靠的方式.答案是这是不可能的.因为您的实际架构如下所示:
You want to know how to get the IP of the server that hosted the Javascript/HTML files before the client downloaded them, presumably in a reliable fashion. And the answer is that this is not possible. Because your actual schema looks like this:
[JAVASCRIPT BASED WEBSITE] <--------> [USER]
192.168.0.3 192.168.0.123
^
|
[REST SERVER] <--------------------------+
192.168.0.2
这篇关于如何获取REST消费者的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!