Libcurl Returns 损坏的数据

Libcurl Returns Corrupt Data

curl_easy_setopt(m_pCurl,   CURLOPT_URL, szURL);
curl_easy_setopt(m_pCurl,   CURLOPT_UPLOAD,0);
curl_easy_setopt(m_pCurl,   CURLOPT_WRITEFUNCTION, s_Write_Data);
curl_easy_setopt(m_pCurl,   CURLOPT_WRITEDATA, this);
curl_easy_setopt(m_pCurl, CURLOPT_CONNECTTIMEOUT, 10);
curl_easy_setopt(m_pCurl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(m_pCurl, CURLOPT_PROGRESSFUNCTION, s_Progress);
curl_easy_setopt(m_pCurl, CURLOPT_PROGRESSDATA, this);
curl_easy_setopt(m_pCurl, CURLOPT_HTTP_CONTENT_DECODING, 0L);

以上是我对转移的所有选择。下载 returns 一个 .tar.gz 文件,使用命令行 curl 或 WGET returns 绝对没问题,使用 libcurl 返回的数据大约 8k 短,执行 cmp 显示 2 个文件在内部更改前 10 个字节。现在已经看了 2 天了,没有任何希望的迹象。尝试了各种不同的选项组合。

s_Write_Data 实现为:

size_t CCurlManager::s_Write_Data(void *buffer, size_t size, size_t nmemb, void *userp)
{

    CCurlManager *pThis = reinterpret_cast<CCurlManager *>(userp);
    return pThis->WriteData(buffer, size, nmemb);


}

我从 c​​url verbose 得到的响应头:

HTTP/1.1 200 OK

Date: Mon, 17 Dec 2018 13:56:39 GMT

Server: Apache/2.2.13 (Linux/SUSE)

X-Powered-By: PHP/5.4.20

Content-Length: 393800

Content-Disposition: attachment; filename="test.tar.gz"

Connection: close

Content-Type: application/octet-stream

这是 wxString (wxWidgets) 的一个问题,wxString(char*, int) 为最多 int 字符创建一个 char* 字符串,或者直到达到 null char,这是非标准的(char*, int) 字符串构造函数,只读取 int 字符。

基本上,我在 WriteData 函数中创建的字符串在到达空字符时终止。