【发布时间】:2020-01-04 10:23:29
【问题描述】:
我正在尝试通过从 Dropbox 或谷歌驱动器中的共享链接下载更新文件来实现自动更新。起初,我使用 Windows API 函数 URLDownloadToFile() 从 Web 下载公共文件。它工作正常,但是当我将它用于云文件时,它没有下载文件。而是得到一个 HTML 文件,当使用浏览器打开时,我可以使用浏览器下载该文件。
所以,我转而使用 Libcurl 库并按照他们的教程进行操作。我总是收到错误
(60) : CURL_PEER_FAILED_VERIFICATION。
我按照https://curl.haxx.se/libcurl/c/url2file.html 的示例进行操作。并尝试获取相同的公共文件,我已经下载了 Windows API,但仍然收到相同的错误。所以我知道这与服务器身份验证或类似问题无关。
这是我同时使用 windows api 和 Libcurl 的下载功能:
static size_t write_data (void *ptr,size_t size,size_t nmemb,void* stream)
{
size_t written = fwrite (ptr,size,nmemb,(FILE *) stream) ;
return written ;
} /* write_data */
int DownloadFile ()
{
static const char FileURL[] = "https://www.pexels.com/photo/618608/download/?search_query=park&tracking_id=6qgsqm6nzau" :
static char TargetURL[] = "D:\\Download\\DownloadURL\\Test.jpg" ;
static char TargetCURL[] = "D:\\Download\\DownloadCURL\\Test.jpg" ;
// Download the file using windows function into DownloadURL folder
URLDownloadToFile (nullptr,FileURL[2],TargetURL,0,nullptr) ; // OK
// Download the file using curl library into DownloadCURL folder
if (auto curl = curl_easy_init ()) {
auto fp = fopen (TargetCURL,"wb") ;
curl_easy_setopt (curl,CURLOPT_URL,FileURL[1]) ;
curl_easy_setopt (curl,CURLOPT_FAILONERROR,1) ;
curl_easy_setopt (curl,CURLOPT_WRITEDATA,fp) ;
/* Perform the request, res will get the return code */
auto res = curl_easy_perform (curl) ; // Always Fail
fclose (fp) ;
curl_easy_cleanup (curl) ;
} /* if (auto curl = curl_easy_init ()) */
return true ;
} /* Download */
我的系统运行的是 Windows 10 x64。我使用 Visual Studio 2017,Libcurl 修订版 7.67 和 openSSL。
谁能帮我弄清楚缺少什么?
【问题讨论】: