【问题标题】:unhandled exception using cURL (curl_easy_perform)使用 cURL 的未处理异常 (curl_easy_perform)
【发布时间】:2015-12-11 04:50:33
【问题描述】:
std::string DownloadFile(std::string Fname, std::string Furl)
{
            CURL *curl;
            CURLcode res;
            const char *url = Furl.c_str();
            curl = curl_easy_init();
            if (curl) {
                FILE * pFile;
                pFile = fopen(Fname.c_str(),"wb");
                if (pFile!=NULL) {
                    curl_easy_setopt(curl, CURLOPT_URL, url);
                    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
                    curl_easy_setopt(curl, CURLOPT_WRITEDATA, pFile);
                    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
                    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func);
                    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
                    char errbuf[CURL_ERROR_SIZE];
                    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
                    res = curl_easy_perform(curl);
                    std::string xres = curl_easy_strerror(res);
                    curl_easy_cleanup(curl);
                    fclose(pFile);
                    return xres;
                }
            }
}

我收到此错误:

“System.AccessViolationException”类型的未处理异常 发生在 Fourth.exe 附加信息:试图读取或 写受保护的内存。这通常表明其他内存 已损坏。

上线:

res = curl_easy_perform(curl);

任何想法我哪里出错了?

【问题讨论】:

    标签: exception visual-c++ curl


    【解决方案1】:

    这很可能与您的 curl 选项之一有关,我会查看您添加的明显选项,例如 CURLOPT_WRITEFUNCTIONCURLOPT_WRITEDATACURLOPT_ERRORBUFFER。我最初的评论是错误的:/

    【讨论】:

    • 所有这些选项似乎都是正确的,并且通过了调试语法检查...仅在运行时出错
    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 2011-11-19
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-16
    相关资源
    最近更新 更多