我用curl下载文件,CURLcode res = curl_easy_perform(curl);这一行代码返回的是res = CURLE_OK,
但是下载到的文件和服务器上的文件并不一样有可能是什么原因呢,请指教,谢谢了!
我的代码调用如下:
//设置curl的下载选项
curl_easy_setopt(curl, CURLOPT_URL, srcUrl.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fileWriteFunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fDesc.fp);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, downloadProgressFunc);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
if (_connectionTimeout) {
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, _connectionTimeout);
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, LOW_SPEED_LIMIT);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, LOW_SPEED_TIME);
//启动curl下载
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK) {
_fileUtils->removeFile(data.path + data.name + TEMP_EXT);
std::string msg = cocos2d::StringUtils::format("Unable to download file: %s", curl_easy_strerror(res));
this->notifyError(msg, customId, res);
}
fclose(fDesc.fp);
curl_easy_cleanup(curl);
if (res == CURLE_OK) {
_fileUtils->renameFile(data.path, data.name + TEMP_EXT, data.name);
cocos2d::Director::getInstance()->getScheduler()->performFunctionInCocosThread(=]{
if (!ptr.expired()) {
std::shared_ptr<Downloader> downloader = ptr.lock();
auto successCB = downloader->getSuccessCallback();
if (successCB != nullptr) {
successCB(data.url, data.path + data.name, data.customId);
}
}
});
}