Getting curl: (6) Failed to resolve host: localhost
Getting curl: (6) Failed to resolve host: localhost
I am facing a problem when calling a local url via curl
. I checked this question but it didn't help me.
My curl command:
curl --data "ip=127.0.0.1&device_type=web" http://localhost/api/users/getToken.json
Also tried the solution in this selected answer: StackOverflow question.
curl -H "Content-Type: application/json" --data "ip=127.0.0.1&device_type=web" http://localhost/api/users/getToken.json
However, the above command works if I run it using the IP address
curl --data "ip=127.0.0.1&device_type=web" http://192.168.1.1/api/users/getToken.json
Any help why this doesn't work when using localhost?
source to share
I was getting the same error and found that mine /etc/hosts
did not have a localhost mapping that it should have.
If you run cat/etc/hosts
and if it doesn't show you a line with the following content, then you have the same problem as mine:
127.0.0.1 localhost
To fix this, just add a line similar to the previous one to the file /etc/hosts
. You can also do this by running:
sudo echo "127.0.0.1 localhost" >> /etc/hosts
source to share