curl http_code of 000
The response 000 indicates that cURL failed to execute for some reason. In such a case, you should test for cURL exit code rather than making assumptions. See the "Exit Codes" section of the curl manpage for a full list of exit codes and their meanings.
Failed DNS resolution (6)
$ curl -w "%{http_code}\n" http://example.invalid/ ; echo "Exit code: $?"
000
curl: (6) Could not resolve host: example.invalid
Exit code: 6
(As answered by ILIV)
Connection refused (7)
$ curl -w "%{http_code}\n" http://localhost:81/ ; echo "Exit code: $?"
000
curl: (7) Failed to connect to localhost port 81: Connection refused
Exit code: 7
Connection timed out (28)
$ curl -w "%{http_code}\n" -m 5 http://10.255.255.1/ ; echo "Exit code: $?"
000
curl: (28) Connection timed out after 5001 milliseconds
Exit code: 28
(As answered by Arun)
Server actually returns 000 for some reason (0)
Start a fake server:
$ nc -l -p 65535 & <<EOF
> HTTP/1.1 000 Fake Status Code
> Content-Length: 0
> Connection: close
>
> EOF
Client request:
$ curl -w "%{http_code}\n" http://localhost:65535/ ; echo "Exit code: $?"
000
Exit code: 0
No idea why this would happen in the real world, but hey. If cURL doesn't get a valid status code at all, it assumes 200.
I believe 000 means curl failed to resolve a DNS name:
$ curl -I -w "%{http_code}" https://zxcvsitename.com
curl: (6) Could not resolve host: zxcvsitename.com; Unknown error
000
Note that it returns this code pretty much immediately.
Curl 000 means a timeout: - the timeout could be a result of firewall blocking your request from going out. - the timeout could be a result of a connection drop. - The timeout could also be a result of failing to resolve a dns name.
I worked extensively with curl and I pay close attention to all response codes - 000 is one of them. In my cases I received 000 response code when any of the above three conditions were met.
Infact I'm currently running (as I speak) a curl script testing 2000+ uris. Example from my script (hiding ips and domain names):
Response code from <currentip> to http://<domain_name>/category/gifts/category1/category2/12142/ = 200
Response code from <currentip> to http://<domain_name>/category/gifts/category1/category2/12143/ = 000
Response code from <currentip> to http://<domain_name>/category/gifts/category1/category2/12144/ = 000
Response code from <currentip> to http://<domain_name>/category/gifts/category1/category2/12145/ = 200
If you notice above, the domain_name is same for all URLs. While some URLs throw 000, others throw 200, which clearly means it is not a dns issue.
If I go back and hit the individual URL throwing a 000, I usually get a 200. In this case the reason for a 000 is a connectivity issue.