Skip to content
Advertisement

Does localhost refer to the client or the server?

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.

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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement