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.php
if the client machine is my phone that is in the same Wlan as the server. So does that mean that a request to localhost
from dart code refers to the client machine? I assume so but want to be sure.
Advertisement
Answer
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.