dongmou9260
2015-07-03 16:09
浏览 139
已采纳

localhost是指客户端还是服务器?

I have a Dart application, which communicates to the server with POST-requests. At the moment, the server is on my local machine where I also test the application in the browser, so obviously, I have to send the POST-Req to localhost. But when the server is on one computer and the client anywhere else, it seems not to work with localhost even though both the webapp and the server are hosted on the same machine.

For example, I have to replace localhost:8080/web/info.php with 192.168.0.6/web/info.phpif the client machine is my phone that is in the same Wlan as the server. So does that mean that a request to localhostfrom dart code refers to the client machine? I assume so but want to be sure.

图片转代码服务由CSDN问答提供 功能建议

我有一个Dart应用程序,它通过POST请求与服务器通信。 目前,服务器在我的本地机器上,我也在浏览器中测试应用程序,所以很明显,我必须将POST-Req发送到localhost。 但是当服务器在一台计算机和其他任何地方的客户端上时,即使webapp和服务器都托管在同一台机器上,它似乎也不适用于localhost。

例如, 我必须用 192.168.0.6/web/info.php 替换 localhost:8080 / web / info.php ,如果客户端机器是我的同一个Wlan的手机 作为服务器。 那么这是否意味着从dart代码对 localhost 的请求是指客户端机器? 我这么认为,但我想确定。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtxw20878 2015-07-03 16:11
    已采纳

    Localhost is just an easy way of identifying the current computer. It does not work when trying to access another server unless you view it from the server itself. If you want to access it from another server, you should either refer to your server by IP, or by a domain name.

    点赞 打赏 评论

相关推荐 更多相似问题