从libcurl获取详细信息到文件
Getting verbose information from libcurl to a file
我正试图在C/C++中开发一个使用libcurl的QT应用程序。简单地说,我想将VERBOSE数据保存到一个文件中。在libcurl API文档中,据说(https://curl.haxx.se/libcurl/c/CURLOPT_VERBOSE.html)
详细信息将发送到stderr,或用CURLOPT_stderr设置的流。
因此,VERBOSE信息将在stderr中。在我关注CURLOPT_STDERR的链接之后(https://curl.haxx.se/libcurl/c/CURLOPT_STDERR.html)告诉,
将FILE*作为参数传递。告诉libcurl在显示进度表和显示CURLOPT_VERBOSE数据时使用此流而不是stderr。
在CURLOPT_STDERR链接中,存在一个代码示例。我在自己的应用程序上尝试过:
CURL *curl = curl_easy_init();
FILE *filep = fopen("dump.txt", "wb");
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.com");
curl_easy_setopt(curl, CURLOPT_STDERR, filep);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_perform(curl);
}
CURLcode res = curl_easy_perform(curl);
if (CURLE_OK != res) {
fprintf(stderr, "curl told us %dn", res);
}
curl_easy_cleanup(curl);
fclose(filep);
但是,详细信息不会显示在命令行中,并且为详细信息创建的文件是空的。我该如何解决这个问题?
以下示例适用于我:
#include <stdio.h>
#include <curl/curl.h>
int main(int argc, char *argv[])
{
CURLcode ret;
CURL *hnd;
FILE* logfile;
logfile = fopen("dump.txt", "wb");
hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_URL, "http://example.org");
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(hnd, CURLOPT_STDERR, logfile);
ret = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
fclose(logfile);
return (int)ret;
}
相关文章:
- std::extent 实现详细信息说明
- VisualC++ 2010 有没有办法找出有关未处理异常错误的更多详细信息
- 如何使用软化工具包从 OPC UA 服务器异步读取操作回调中的数据值响应中获取 NodeId 详细信息
- protobuf,如何在protobuf消息中遍历所有集合字段,我不知道详细信息?(C++)
- AVX2收集指令使用详细信息
- 只知道运行时的数据类型.如何将数据详细信息隐藏到使用它们的其他类
- 如何在文本文件中搜索员工记录(按名称)并仅显示其详细信息?
- 使用TDD时隐藏文件访问实现详细信息
- 显示 txt 文件详细信息
- 为什么 Boost 和其他库的某些部分(如 Folly)在详细信息子文件夹中
- 使用IShellDispatch界面更改文件的详细信息选项卡(右键单击时)?
- 在 C++ 中设置内置 exe 的 Windows 文件详细信息
- 当全局函数需要指向 impl 的指针时,如何防止 impl 详细信息出现在头文件中
- 如何在二进制文件(.net或非托管文件)中注入/更新Version和其他详细信息
- 从 C++ 中的文件中获取特定位置的详细信息
- 如何将字符串行作为cl_uint数组和文件详细信息传递给GPGPU
- 如何从文件中提取薪酬最高的员工的详细信息
- 从libcurl获取详细信息到文件
- 从显示输出中最后一行详细信息的文本文件中读取两次
- 在gdb - c++中打印有关文件流对象的详细信息