sending http request from azure web app to my machine

可紊 提交于 2021-02-11 13:21:56

问题


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.

  1. Build the project locally and monitor port 3000.

  1. Local visit, check the effect.

  1. Access in the virtual machine, discovery failed.

  1. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!