Crash on curl_easy_perform() when uploading a file on CURL i
Crash on curl_easy_perform() when uploading a file on CURL in C++
当通过C 中的curl库上传文件时,我遇到了崩溃的问题。我正在使用此位置的确切演示代码:https://curl.haxx.se/libcurl/c/fileupload.html
我在代码中更改的唯一一件事是上传位置,上传到Windows上的本地WAMP服务器,以及要上传的文件,我已经验证了它的打开确定。
我正在通过Visual Studio 2014跑步,并通过DLL
建立卷曲该程序的输出为:
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> PUT /replayupload.php HTTP/1.1
Host: 127.0.0.1
Accept: */*
Content-Length: 43
Expect: 100-continue
< HTTP/1.1 100 Continue
*然后,我在程序中的第66行中崩溃。看来有线:
res = curl_easy_perform(curl);
正在引起无效参数的问题。我已经验证了卷曲变量不是零的,但是我发现很难获得比这更多的调试信息,呼叫堆栈只引用了DLL中的内存地址。
我能够运行演示以仅上传邮政变量并获取页面,这在没有崩溃的情况下运行良好。崩溃仅在上传文件时发生。
我的确切代码是:
int main(void)
{
CURL *curl;
CURLcode res;
struct stat file_info;
double speed_upload, total_time;
FILE *fd;
fd = fopen("E:\testfiles\test.txt", "rb"); /* open file to upload */
if (!fd)
return 1; /* can't continue */
/* to get the file size */
if (fstat(_fileno(fd), &file_info) != 0)
return 1; /* can't continue */
curl = curl_easy_init();
if (curl) {
/* upload to this place */
curl_easy_setopt(curl, CURLOPT_URL,
"http://127.0.0.1/testupload.php");
/* tell it to "upload" to the URL */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* set where to read from (on Windows you need to use READFUNCTION too) */
curl_easy_setopt(curl, CURLOPT_READDATA, fd);
/* and give the size of the upload (optional) */
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);
/* enable verbose for easier tracing */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %sn",
curl_easy_strerror(res));
}
else {
/* now extract transfer info */
curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
fprintf(stderr, "Speed: %.3f bytes/sec during %.3f secondsn",
speed_upload, total_time);
}
/* always cleanup */
curl_easy_cleanup(curl);
}
fclose(fd);
return 0;
}
感谢tkausl发现行
/* set where to read from (on Windows you need to use READFUNCTION too) */
我将此行添加到我的代码
curl_easy_setopt(curl, CURLOPT_READFUNCTION, &fread);
现在一切似乎都起作用。
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 循环挂起迭代的 std::擦除 on std::list
- SIGSEGV on Boost UDP 套接字关闭 - tcache_get at malloc.c.
- CPP 中的瓦尔格林德和记忆泄漏:"Conditional jump or move depends on uninitialised values"
- std::bind on statd::array 的运算符 []
- 您将如何连接"on the fly"文本+整数并将其传递给函数?
- 如何修复输出日志中的"EnableInput can only be specified on a Pawn for its Controller"错误
- VS2019 - Sudo Remote Debugging on Linux with Cmake project
- C++ library with Tensorflow on Android
- SFML 交叉编译 for Windows on Linux.
- How to recover system gcc compiler on centos 6
- Cmake with Flex/Bison on windows
- 按原样保存用户输入 - Ruby on Rails
- OpenAL C++ on Linux
- Boost::process on Windows - with MinGW?
- CMake on FindOpenGL.cmake 中的错误,当使用导入的目标 OpenGL::GLU?
- Utilization of atomic_flag on C++
- anaconda cythonize C++ on windows 10
- CMake & MinGW Compileilation on Windows,无需 -G "MinGW Makefiles"标志
- Crash on curl_easy_perform() when uploading a file on CURL i