开发者

Curl CURLE_COULDNT_RESOLVE_HOST in debug mode

I am using curl to access a file in a specified url. I use VC++ 2010 and curl 7.21.2 (I compiled it myself) with wxWidgets for user interface (all built in unicode except curl). I have no problem in my release build but the same code (below) fails in debug build with CURLE_COULDNT_RESOLVE_HOST error for the same url.

Here is the code:

CURL * pEasyHandle = curl_easy_init();
if(!pEasyHandle) 
    return wxEmptyString;

CURLcode curlcode; 
curlcode = curl_easy_setopt(pEasyHandle, CURLOPT_VERBOSE, 1); // this is in ifdef _DEBUG actually

curlcode = curl_easy_setopt(pEasyHandle, CURLOPT_HTTPGET, 1);

curlcode = curl_easy_setopt(pEasyHandle, CURLOPT_URL, url.ToStdString()); 

curl_easy_setopt(pEasyHandle, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(pEasyHandle, CURLOPT_TIMEOUT, 10);
curl_easy_setopt(pEasyHandle, CURLOPT_CONNECTTIMEOU开发者_运维百科T , 10);

wxString fileListString = wxEmptyString;
curl_easy_setopt(pEasyHandle, CURLOPT_WRITEDATA, &fileListString);

curlcode = curl_easy_perform(pEasyHandle); // post away!

if(curlcode == CURLE_OK)
{
          // cannot enter here in debug mode
}
else
{
    m_errorString = curl_easy_strerror(curlcode);
    wxMessageBox(m_errorString);
}

curl_easy_cleanup(pEasyHandle);


The following line seems to be the problem:

curlcode = curl_easy_setopt(pEasyHandle, CURLOPT_URL, url.ToStdString());

If my assumptions are correct, ToStdString returns an std::string and not a C string. curl is a C library, so it expects char *-s.

Could you tell what type url is?


You can replace url.ToStdString() with url.c_str().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜