How to troubleshoot connectivity when curl gets an *empty response*

Solution 1:

You likely will need to troubleshoot this from the server side, not the client side. I believe you are confusing an 'empty response' with 'no response'. They do not mean the same thing. Likely you are getting a reply that does not contain any data.

You can test this by simply using telnet instead of going through curl:

telnet 111.222.159.30 80

Once connected, paste the following (taken from your curl output):

GET / HTTP/1.1
User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.19.0     OpenSSL/0.9.8h zlib/1.2.3 libidn/1.10
Host: 111.222.159.30
Accept: */*

You should see the response exactly as curl sees it.

One possible reason you are getting an empty reply is that you're trying to hit a website that is a name-based virtual host. If that's the case, depending on server configuration (the site you're trying to hit happens to be configured as the default) you cannot reach the site by IP address without a little bit of work.

You can test that on the client side by simply changing the 'Host' line above; replace www.example.com with the site you're trying to reach:

GET / HTTP/1.1
User-Agent: curl/7.19.0 (x86_64-suse-linux-gnu) libcurl/7.19.0     OpenSSL/0.9.8h zlib/1.2.3 libidn/1.10
Host: www.example.com
Accept: */*

Solution 2:

Curl is fine, but doesnt give much feedback when things go wrong. (As you can tell) wget may give you more information, but as yoonix mentions, Server side (ie webserver error logs) is the place to look.

wget -S -O /dev/null http://www.example.com

You can set hostnames as well with

wget -s -O /dev/null --header="Host: foo.bar" http://www.example.com

Solution 3:

Try this -> Instead of going through cURL, try pinging the site you’re trying to reach with Telnet. The response that your connection attempt returns will be exactly what cURL sees when it tries to connect (but which it unhelpfully obfuscates from you). Now, depending on what what you see here, you might draw one of several conclusions:

You’re attempting to connect to a website that’s a name-based virtual host, meaning it cannot be reached via IP address. Something’s gone wrong with the hostname – you may have mistyped something. Note that using GET instead of POST for parameters will give you a more concrete answer.

The issue may also be tied to the 100-continue header. Try running curl_getinfo($ch, CURLINFO_HTTP_CODE), and check the result.