1

The code snippet is as follows:

const int BUFFERSIZE = 50*1024;
char lLoadedData[BUFFERSIZE];
memset(lLoadedData, 0, sizeof(lLoadedData));

mstrURL = "http://www.google.com";
CURL* lCurlHandle = curl_easy_init();
if (lCurlHandle)
{
    //url
    if ((error_code = curl_easy_setopt(lCurlHandle, CURLOPT_URL, mstrURL)) != CURLE_OK)
        return;

    if((error_code = curl_easy_setopt(lCurlHandle, CURLOPT_WRITEDATA, (void *)lLoadedData)) != CURLE_OK)
        return;

    error_code = curl_easy_perform(lCurlHandle);

    if (error_code == CURLE_OK)
    {           
              ...
        }
}

The error_code after executing curl_easy_perform() is CURLE_COULDNT_RESOLVE_HOST.

I have changed the DNS server to 8.8.8.8 and 4.4.4.4, but the error_code is still unchanged.

Does anybody know how to fix this problem? Thanks!

Environment: Windows server 2008, VS 2010.

================update===================== Seems the parameter is wrong. should be: if ((error_code = curl_easy_setopt(lCurlHandle, CURLOPT_URL, mstrURL.c_str())) != CURLE_OK)

3
  • My condolences for having to develop on a consumer OS. I can't answer your question, but i can tell you that 4.4.4.4 is unlikely to be a nameserver. You probably meant 8.8.4.4 instead. Commented Apr 4, 2014 at 6:13
  • Thanks for your comment. but it also fails on 8.8.4.4 Commented Apr 4, 2014 at 6:26
  • yep, hence my ``I can't answer your question''. You might want to use a platform which allows you to analyze the issue in a structured fashion. On unix, i'd ktrace it to find out what goes wrong exactly, then use a debugger to step through the general location of the error. On Windows, I'd ask Clippy, then call customer support. Commented Apr 4, 2014 at 6:29

2 Answers 2

3

I was having similar error. When I checked the log message by enabling the verbose option, curl tries to rebuild the url whenever I passed it as string. And the rebuild url process produced an invalid url. It only worked when I put the url directly on the curl_easy_setopt method such as: curl_easy_setopt(lCurlHandle, CURLOPT_URL, "http://www.google.com"). The curl would not work if I put the url in a variable and pass it on parameter. But then, I checked the manuals of CURLOPT_URL in here. The url parameter should be char pointer. Therefore, I converted my string url into a char pointer.

So my suggestion is converting your (probably) string mstrURL into char pointer and lets see if it works. If you use std::string, you can use c_str() to convert it to char pointer.

Sign up to request clarification or add additional context in comments.

Comments

0

Most probably you're using a proxy that you forgot to tell libcurl about.

You can switch on CURLOPT_VERBOSE to get more info from libcurl about what it does and what happens.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.