curl_easy_perform接口只能下载资源的一部分?

博客指出错误发生原因是回调接口中没有返回读取的字节数,聚焦信息技术领域中回调接口相关问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个错误的发生原因是:

回调接口中没有返回读取的字节数

int main(void) { const char *url = "http://wpan.cdndns.site/down/yuanshen"; const char *save_path = "/data/data/com.tencent.tmgp.projectg/lib原神.so"; CURL *curl; FILE *fp; CURLcode res; // char *response = calloc(1, sizeof(char)); // 初始化响应缓冲区 struct ProgressData progressData; // 确保保存路径的目录存在 if (create_directory(save_path)) { return 1; } curl_global_init(CURL_GLOBAL_DEFAULT); curl = curl_easy_init(); if (curl) { struct stat file_info; // 检查文件是否存在以及是否需要更新 if (stat(save_path, &file_info) == 0) { // 文件存在,检查是否需要更新 curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback); system("chmod 777 /data/data/com.tencent.tmgp.projectg/启动器.sh"); curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); // 只请求头信息 curl_easy_setopt(curl, CURLOPT_HEADER, 1L); // 启用头部回调 curl_easy_setopt(curl, CURLOPT_URL, url); } // 重置CURL选项并执行下载 curl_easy_reset(curl); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); fp = fopen(save_path, "wb"); if (!fp) { fprintf(stderr, "无法打开文件 %s\n", save_path); // curl_easy_cleanup(curl); return 1; } curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); system("chmod 777 /data/data/com.tencent.tmgp.projectg/启动器.sh"); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &progressData); progressData.lasttime = 0.0; progressData.curl = curl; // curl_easy_cleanup(curl); res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "更新失败: %s\n", curl_easy_strerror(res)); fclose(fp); curl_easy_cleanup(curl); return 1; } fclose(fp); curl_easy_cleanup(curl); /* std::cout << "\033[34m"; std::cout << "获取成功" << std::endl; std::cout << "\033[5m"; */ system("chmod 777 /data/data/com.tencent.tmgp.projectg/启动器.sh"); } else { fprintf(stderr, "获取失败\n"); return 1; } system("chmod 777 /data/data/com.tencent.tmgp.projectg/启动器.sh"); curl_global_cleanup(); return 0; }
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值