Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl_easy_perform: Couldn't resolve host name

Tags:

c++

libcurl

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.

The URL in question: http://servermods.cursecdn.com/files/922/48/worldedit-bukkit-6.1.3.jar

The relevant code:

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);
like image 472
Max Roncace Avatar asked Sep 25 '16 03:09

Max Roncace


1 Answers

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.

like image 51
Max Roncace Avatar answered Oct 24 '22 01:10

Max Roncace