Reputation: 3469
Getting curl: (6) Could not resolve host: localhost
I'm facing an issue when calling a localhost url through curl
. I did check 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 : https://stackoverflow.com/a/40078901/1225070
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 is working 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 is not working when using localhost?
Upvotes: 7
Views: 15583
Reputation: 3840
I was getting the same error and figured out my /etc/hosts
didn't have the localhost mapping it was supposed to 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 I had:
127.0.0.1 localhost
To fix this just add a line like the previous one to your /etc/hosts
file. You can also to this by running:
sudo echo "127.0.0.1 localhost" >> /etc/hosts
Upvotes: 4