2

我正在编写一个使用 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);
}
4

0 回答 0