Libcurl在C代码中返回“从对等端接收数据时失败”

时间:2012-11-16 08:39:54

标签: c libcurl

我正在编写一个使用libcurl发送HTTP POST请求的C程序。使用以下两种方法,我可以在不同的时间上传两个不同的文件。我能够在Windows 7中完成它,不知何故,当它在Windows XP SP3中运行时,它会返回一个错误:

  

从对等方接收数据时失败。

void sendFile()
{
    struct curl_httppost *post=NULL;
    struct curl_httppost *last=NULL;
    CURL *curlfile;
    CURLcode response;

    // Get a curl handle
    curlfile = curl_easy_init();
    curl_easy_setopt(curlhash, CURLOPT_URL, URL);

    curl_formadd(&post, &last,
        CURLFORM_COPYNAME, "file1",
        CURLFORM_FILECONTENT, "C:\\file1.txt",
        CURLFORM_END
        );

    curl_easy_setopt(curlfile, CURLOPT_HTTPPOST, post);

    response = curl_easy_perform(curlfile);
    curl_formfree(post);
    curl_easy_cleanup(curlfile);
}


void sendFileTwo()
{
    CURL *curlpost;
    CURLcode response;
    struct curl_httppost *post=NULL;
    struct curl_httppost *last=NULL;

    // Get a curl handle
    curlpost = curl_easy_init();
    curl_easy_setopt(curlpost, CURLOPT_URL, URL);

    curl_formadd(&post, &last,
        CURLFORM_COPYNAME, "File2", 
        CURLFORM_FILE, "C:\\file2.txt", 
        CURLFORM_END
        );

    curl_easy_setopt(curlpost, CURLOPT_HTTPPOST, post);
    response = curl_easy_perform(curlpost);
    curl_formfree(post);
}

0 个答案:

没有答案