问题
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}`));
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
回答1:
This problem has nothing to do with your webapp.
So I will not test the webapp program anymore, you can access your http request of http://*mypublicip*:3000/write/' + Name
through other machines (not PCs in the LAN) , My test environment is vm built in azure. You will find that your request cannot be accessed successfully.
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.
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.
To solve your problem, I used ngrok
.
- Build the project locally and monitor port
3000
.
- Local visit, check the effect.
- Access in the virtual machine, discovery failed.
- After installing ngrok, the virtual machine accesses the new address and it succeeds.
First allow port 3000 to be exposed.
Test in vm, it works.
来源:https://stackoverflow.com/questions/65093518/sending-http-request-from-azure-web-app-to-my-machine