(我在windows下)我正在尝试下载位于给定网址的zip文件,如下所示:
CURL *curl;
FILE *fp;
CURLcode res;
char *url = "https://www.markit.com/news/InterestRates_USD_20090102.zip";
char outfilename[FILENAME_MAX] = "C:\\InterestRates_USD_20090102.zip";
curl_version_info_data * vinfo = curl_version_info(CURLVERSION_NOW);
if (vinfo->features & CURL_VERSION_SSL)
{
printf("CURL: SSL enabled\n");
}
else {
printf("CURL: SSL not enabled\n");
}
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); //Prevent "longjmp causes uninitialized stack frame" bug
fp = fopen(outfilename, "wb");
int errnum = 0;
if (nullptr == fp)
{
errnum = errno;
fprintf(stderr, "Value of errno: %d\n", errno);
perror("Error printed by perror");
fprintf(stderr, "Error opening file: %s\n", strerror(errnum));
}
curl_easy_setopt(curl, CURLOPT_CAINFO, "./ca-bundle.crt");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
确实出现了文件C:\\InterestRates_USD_20090102.zip
,但它是一个名为InterestRates_USD_20090102.zip
的目录,而不是一个zip文件。
我不认为问题是zip格式,而是https网址(我当然手动下载文件没有问题),因为res
在调试时显示CURLE_UNSUPPORTED_PROTOCOL
。我确实尝试了很多没有https的文件格式并且没有问题,而任何带有https的文件格式都会在调试时给我CURLE_UNSUPPORTED_PROTOCOL
...
我找到了这个页面:
但无法适应,因为支持页面的安全性详细信息(在chrome - >开发人员选项 - >安全性下)产生了不兼容的证书(不是crt格式)
请注意,我是否使用了" DLL"或者" DLL Windows SSPI - DLL WinIDN",后者包括windows sll,请参见:Curl 7.43.0 won't build in MSVC 2013