curl_easy_perform:无法解析主机名 [英] curl_easy_perform: Couldn't resolve host name
问题描述
libcurl
有点奇怪的问题-它拒绝解析特定的URL,并返回错误消息无法解析主机名".解决其他主机没有问题.我怀疑原因是失败的URL返回了302重定向,但我已经设置了适当的选项来遵循它.
I'm having a bit of an odd issue with libcurl
- it's refusing to resolve a particular URL, returning the error message "Couldn't resolve host name." It has no issues resolving other hosts. I suspect the reason is that the URL which fails returns a 302 redirect, but I've set appropriate options for it to be followed.
有问题的网址: 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
需要 CURLOPT_URL
的 char *
.我的代码正在传递 string
.这实质上会导致库错误地解释字符串,并且无法解析主机.
libcurl
expects a char*
for CURLOPT_URL
. My code was passing a string
. This essentially causes the library to misinterpret the string and fail to resolve the host.
这篇关于curl_easy_perform:无法解析主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!