Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting curl: (6) Could not resolve host: localhost

Tags:

curl

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?

like image 546
elegant-user Avatar asked Jul 22 '17 10:07

elegant-user


People also ask

Could not resolve host cURL error 6?

cURL error 6. The error indicates that the network that UpdraftPlus is attempting to connect to is unreachable. This shows that the connection isn't being blocked, but is failing to reach the UpdraftPlus.com servers.

Could not resolve host reason?

This error means that the hostname you are trying to connect to cannot be resolved to an IP address. (Hostnames are resolved to IP addresses by a DNS (Domain NameServer)). Please check what you have entered in the Address field. You will need the valid hostname of an FTP server or a valid IP address.

Can't resolve host Kali Linux?

Solution: Please make sure you have an active Internet connection and your Kali DNS settings are correct. We recommend using Google public DNS servers. Please set both DNS servers to 8.8.

Can not Resolve host Ubuntu?

Since the hostname is missing and your system is not able to figure out the hostname and thus it throws the error 'sudo: unable to resolve host'. To fix this error, edit the /etc/hosts file and set the hostname (newpc) with a loopback address (127.0. 0.1).


1 Answers

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
like image 111
Bonifacio2 Avatar answered Sep 20 '22 22:09

Bonifacio2