如何从移动设备向本地主机发送 POST 请求?
我正在尝试在 React Native + Flask 应用程序中实现登录。我有一个用于服务器 API 的 docker 容器。我已经在我的计算机的本地主机上运行它。我也在博览会上运行我的前端。由于它是不同的主机,我如何将 POST 请求从我的移动设备(expo)发送到我计算机中本地主机上运行的服务器?
Docker 服务器在容器中的端口 5000 上运行。我已将本地端口 5000 映射到容器的 5000 端口。
I'm trying to implement a login in react native + flask app. I have a docker container for my server API. I've run it on my localhost in my computer. I'm also running my front-end on expo. Since it's a different host, how can i send POST request from my mobile device (expo) to the server running on localhost in my computer?
Docker server runs in port 5000 in container. I've mapped the local port 5000 to container's 5000 port.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我希望您在 docker 容器中公开正确的服务器端口。
然后,通过使用家庭网络中的本地计算机 IP 地址而不是“localhost”即可轻松完成此操作。也许您的防火墙设置必须更改。
对于 React,我通常将服务器 IP 保存在 .env 中,因此对于生产,我可以轻松切换服务器
First of all I hope you are exposing the correct server ports in the docker container.
Then, it can be easily done by using you local machine IP address in your home network instead of "localhost". Maybe your Firewall settings must be changed.
For
React
I usually save the server IP in an .env, so for production I can easily switch the server