curl_easy_perform: 无法解析主机名
curl_easy_perform: Couldn't resolve host name
我在使用 libcurl
时遇到了一些奇怪的问题 - 它拒绝解析特定的 URL,返回错误消息 "Couldn't resolve host name." 它在解析其他主机时没有问题.我怀疑原因是 URL 失败 returns 302 重定向,但我已经设置了适当的选项以供遵循。
有问题的URL:http://servermods.cursecdn.com/files/922/48/worldedit-bukkit-6.1.3.jar
相关代码:
CURL* curl;
FILE* data;
std::string url;
// ...
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_FILE, data);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
CURLcode res = curl_easy_perform(curl);
libcurl
期望 char*
对应 CURLOPT_URL
。我的代码传递了 string
。这实质上会导致库误解字符串并无法解析主机。
我在使用 libcurl
时遇到了一些奇怪的问题 - 它拒绝解析特定的 URL,返回错误消息 "Couldn't resolve host name." 它在解析其他主机时没有问题.我怀疑原因是 URL 失败 returns 302 重定向,但我已经设置了适当的选项以供遵循。
有问题的URL:http://servermods.cursecdn.com/files/922/48/worldedit-bukkit-6.1.3.jar
相关代码:
CURL* curl;
FILE* data;
std::string url;
// ...
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_FILE, data);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
CURLcode res = curl_easy_perform(curl);
libcurl
期望 char*
对应 CURLOPT_URL
。我的代码传递了 string
。这实质上会导致库误解字符串并无法解析主机。