3

I am trying to write a C++ program to read from a website using cURL. I have started with using the code from the cURL example simple.c. If I use that code exactly, no matter what URL I try to access, I obtain error #52: "empty reply from server". This is for any URL I try. If I use cURL from the command line, it seems to work fine.

The verbose response of my program is:

*About to connect() to www.google.com port 80 (#0)
* Trying 74.125.91.99...* connected
*connected to www.google.com (74.125.91.99) port 80 (#0)
>GET / HTTP/1.1
Host: www.google.com
Accept: */*

* Empty reply from server
* Connection #0 to host www.google.com left intact
* server returned nothing (no headers, no data)
*Closing connection #0

The code is:

CURL *curl; 
CURLcode res;

curl = curl_easy_init(); 
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com"); 
curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl); 
4
  • That code works perfectly for me. Outputs the page to STDOUT without a problem. (With the exception that TRUE wasn't defined, but using 1 worked) Commented May 8, 2011 at 20:16
  • It looks perfectly fine to be, too Commented May 8, 2011 at 20:25
  • Aaaaarghh, try to remove the CURLOPT_VERBOSE flag. Some versions (I can't remember which exactly) have awful bug using CURLOPT_VERBOSE flag, set to 1. Try without it. Also, which is the curl'a version? Commented May 8, 2011 at 20:28
  • I tried removing the verbose flag, and it still didn't work. Commented May 8, 2011 at 20:35

2 Answers 2

6

"Empty reply from server" means that libcurl didn't receive any response from the server after it sent off its request. In HTTP every request always gets something back so this is not even responding with HTTP and is thus a rather sever error.

You use a very old libcurl so possibly you're experiencing a bug that existed back then.

Other possible reasons for this is that something in your network/setup is preventing this from working, like a firewall.

Sign up to request clarification or add additional context in comments.

2 Comments

I will try a newer version to see if that fixes the problem
Upgrading to the most recent version (7.21.6) seemed to fix the problem, Thanks!
5

I lost a couple hours debugging an empty response from curl, so I'm sharing here to hopefully prevent the same from happening to others.

I noticed that OPTIONS calls were returned with the "Empty reply from server" error in both the browser and from curl on my machine, but worked fine from a colleague's. When I tried to telnet to port 80 on the web server, the connection would immediately close as soon as I hit ENTER after typing the "OPTIONS /path/to/resource HTTP/1.1" line. Doing an "lsof -i | grep telnet" (with the telnet session open, before typing the OPTIONS line), I saw that my telnet session was to something local, NOT the server I'd specified. I knew something REALLY strange was going on then. Turns out it was because I had Cisco AnyConnect VPN software installed. The VPN need not be running--merely having it installed was enough for it in intercept my traffic. Nasty. A little googling turned up this page, which talks more about the issue:

http://www.bennadel.com/blog/2559-cisco-anyconnect-vpn-client-may-block-cors-ajax-options-requests.htm

So, short story is: it might not be the server...something local could be intercepting and blocking your network traffic.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.