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);
以上是我对转移的所有选择。下载返回一个 .tar.gz 文件,使用命令行 curl 或 WGET 返回绝对正常,使用 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);
}
我从 curl 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 函数中创建的字符串在到达空字符时终止。
关于c++ - Libcurl 返回损坏的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53814295/