卷曲下载空的Zip文件

时间:2019-03-03 01:59:57

标签: c++ curl

我正在尝试连接到Intranet站点并使用libcurl下载.zip文件。

我正在连接代码,但是它下载了一个空的.zip文件。为了下载URL上的实际.zip文件,我需要做些什么?如果我在浏览器中导航到dailyinformation/workload.zip,则会下载.zip文件。

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;
}

int main(int argc, char * argv[]) {
    CURL * curl_handle;
    static const char * filename = "C:\\Information\\Data.zip";
    FILE * file;
    curl_global_init(CURL_GLOBAL_ALL);
    curl_handle = curl_easy_init();
    curl_easy_setopt(curl_handle, CURLOPT_URL, "dailyinformation/Workload.zip");
    curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1 L);
    curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1 L);
    curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
    file = fopen(filename, "wb");
    if (file) {
            curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, file);
            curl_easy_perform(curl_handle);
            fclose(file);
    }
    curl_easy_cleanup(curl_handle);
    curl_global_cleanup();
    return 0;
}

0 个答案:

没有答案