简体   繁体   English

如何从外部服务器向本地主机发出请求

[英]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.

相关问题 如何从外部请求使本地服务器可用? - How can I make my localhost server available from external requests? 如何从Opera的外部页面向本地服务器发出跨域请求? - How can I make cross-domain requests to a local server from an external page in Opera? 如何从我的redux动作向GraphQL-server发出请求? - How to make requests to GraphQL-server from my redux action? 如何从我的 Netlify 前端向我的 Heroku 服务器发出请求? - How to make requests to my Heroku server from my Netlify frontend? 如何从AngularJS向本地服务器上的应用发出$ http请求? - How to make $http requests from AngularJS to app on local server? 允许远程服务器通过参数接受来自本地主机的请求 - Allow remote server to accept requests coming from localhost with params 从本地主机或外部服务器上传文件到 Google Cloud Storage - Uploading files to Google Cloud Storage from Localhost or external server 我该怎么做<link>停止将外部链接附加到本地主机 - How can I make <Link> to stop appending external link to localhost 将外部内容加载到本地主机上的服务器 - Loading external content into server on localhost 如何发出服务器端API请求? - How to make server-side API requests?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM