curl下载的文件总是空的

时间:2011-11-17 06:06:32

标签: c curl

在以下示例之后,我尝试使用curl复制文件:

CURL *curl;
FILE *fp;
CURLcode res;
char *url = "http://localhost/aaa.txt";
char outfilename[FILENAME_MAX] = "D:\\bbb.txt";

curl = curl_easy_init();

if(curl)
{
    fp = fopen(outfilename,"wb");
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
    fclose(fp);
}

它创建一个名为bbb.txt的文件,但该文件为空。你能帮帮我吗?我的错是什么?

1 个答案:

答案 0 :(得分:0)

您错过了对curl_easy_perform的来电。请参阅API description