从 azure web 应用程序向我的机器发送 http 请求 [英] sending http request from azure web app to my machine
问题描述
我创建了一个发送 http 请求的 azure web 应用程序:
I created an azure web app which send an http request:
axios.post('http://*mypublicip*:3000/write/' + Name, {
content: data[1]
})
同时我的电脑有一个正在运行的快速服务器:
meanwhile my computer has a running express server:
app.listen(3000, () => console.log(`Server running on port ${port}`));
当我通过将请求发送到本地主机而不是我的 ip 在本地使用它时,我的所有功能都可以正常工作.我还尝试将主机0.0.0.0"添加到我的 app.listen.我错过了什么?谢谢
all my functionality works when I use it locally by sending the request to localhost instead of my ip. I also tried adding host '0.0.0.0' to my app.listen. what am I missing? thanks
推荐答案
这个问题和你的webapp无关.
所以我不再测试webapp程序了,你可以通过其他机器(不是局域网中的PC),我的测试环境是Azure内置的vm.你会发现你的请求无法成功访问.
原因是你在cmd
中ipconfig
找到的ip
不应该是你的主机ip
,但是运营商分配给你的互联网ip.这个 ip
被许多主机使用.简单来说,这个ip
不只是你的一台机器.
The reason is that the ip
you found in ipconfig
in cmd
should not be your host ip
, but the Internet ip assigned to you by the operator. This ip
is used by many hosts. Simply put, this ip
is not just one of yours Machines.
所以导致你的问题发生.建议使用内网穿透工具来实现.就是用内网穿透工具暴露你的3000端口.
So cause your problem to happen. It is recommended to use intranet penetration tools to achieve this. It means to use the intranet penetration tool to expose your 3000 port.
为了解决您的问题,我使用了 ngrok
.
- 在本地构建项目并监控端口
3000
.
- 本地访问,查看效果.
- 访问虚拟机,发现失败.
- 安装ngrok后,虚拟机访问新地址,成功.
首先允许3000端口暴露.
在 vm 中测试,它可以工作.
Test in vm, it works.
这篇关于从 azure web 应用程序向我的机器发送 http 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!