[英]How to make requests from an external server to localhost
Is there a way that I can make a GET
request from an external server (like google apps script
) to my local server? 有什么方法可以使我从外部服务器(例如
google apps script
)向本地服务器发出GET
请求?
For example, I would like to make a GET
request on this url: http://localhost:3000/api/get_data
例如,我想对此URL进行
GET
请求: http://localhost:3000/api/get_data
If I do that then I get DNS error
. 如果我这样做,则会收到
DNS error
。 Replacing localhost
with my ip address gives Bad Request
用我的IP地址替换
localhost
Bad Request
The "localhost" address is not accessible from the Internet, so you can't use it. 无法从Internet访问“ localhost”地址,因此无法使用它。 Having your IP instead of "localhost" may work, that depends on the firewall rules of your ISP and on your local machine.
使用IP代替“ localhost”可能会起作用,这取决于ISP的防火墙规则和本地计算机。
The easy way to expose your local machine to internet is either by using SSH (if you have the remote machine that is accessible from Internet, for example, Amazon EC2 instance). 将本地计算机暴露于Internet的简单方法是使用SSH(如果您拥有可从Internet访问的远程计算机,例如Amazon EC2实例)。 You can use
-R
ssh switch for that, something like this ssh -R *:8181:localhost:3000 remote-machine
and you can use " http://remote-machine:8181 " to connect to your app. 您可以为此使用
-R
ssh开关,例如ssh -R *:8181:localhost:3000 remote-machine
并且可以使用“ http:// remote-machine:8181 ”连接到您的应用程序。 See also The Black Magic Of SSH / SSH Can Do That? 另请参见SSH / SSH的黑魔法可以做到这一点? .
。
Another way is to use service like https://ngrok.com/ that will do the remote part for you. 另一种方法是使用https://ngrok.com/之类的服务,它将为您完成远程操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.