c++ - CURL 不返回正确的错误代码

标签 c++ curl libcurl

这里的输出应该不是 0。

因为根据 libcurl 文档,0 是成功的。 http://curl.haxx.se/libcurl/c/libcurl-errors.html

curl_easy_setopt(curl_handle, CURLOPT_PROXY, "socks5://127.0.0.1:9050");

显然 curl_easy_setopt 应该返回 5 即 CURLE_COULDNT_RESOLVE_PROXY

#include <iostream>
#include <string>
#include <curl/curl.h>
using namespace std;
int main()
{
    CURL *curl_handle;
    CURLcode err;
    curl_global_init(CURL_GLOBAL_ALL);
    curl_handle = curl_easy_init();
    err = curl_easy_setopt(curl_handle, CURLOPT_PROXY, "socks5://127.0.0.1:9050");
    cout << err;
}

我是不是漏掉了什么?

最佳答案

谢谢大家的回复。

我在 google 上查看了“CURLE_COULDNT_RESOLVE_PROXY”,发现了一些示例。

原来我必须在每次 curl_easy_setopt 之后调用 curl_easy_perform(curl_handle) 才能获取错误代码。

err = curl_easy_perform(curl_handle);
cout << err;

关于c++ - CURL 不返回正确的错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21052739/

相关文章:

c++ - 如何在安全(C++)中存储加密 key ?

c++ - cpp 这个函数中的奇怪行为

python - 如何处理 pycurl.error - 超时异常?

python - 使用 Postman 与请求发布到 Flask 会填充不同的请求属性

c - 在 libcurl 中处理响应

c++ - 在 VS 2010 C++ 中编译项目时出错

c++ - boost 日志 - 使用severity_channel_logger进行格式化

powershell - 如何在 PowerShell 中将 curl 结果作为变量获取

c - libcurl sftp 文件上传恢复问题

c 使用libcurl curl_easy_perform post,空格和点替换为下划线