我正在尝试编写一个C++程序,使用cURL从网站上读取.我已经开始使用cURL示例simple.c中的代码了.如果我完全使用该代码,无论我尝试访问哪个URL,我都会收到错误#52:"来自服务器的空回复".这适用于我尝试的任何网址.如果我从命令行使用cURL,它似乎工作正常.
我的程序的冗长响应是:
*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
Run Code Online (Sandbox Code Playgroud)
代码是:
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);
Run Code Online (Sandbox Code Playgroud)