0
在windows visual studio 2013中怎麼可能curl_easy_perform返回cannot_resolve主機,但是在同一臺pc中相同的代碼在ubuntu虛擬機中工作正常嗎?libcurl在ubuntu虛擬機上工作完美,但無法解析Windows上的主機
CURL *curl;
curl_global_init(CURL_GLOBAL_SSL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_URL, "https://myhost.com/api/login/");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
// calculate request header
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"username\":\"name\", \"password\":\"test\"}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); // set callback
curl_easy_perform(curl); // perform request
curl_easy_cleanup(curl); // cleanup request
return 0;
PROGRAMM的詳細輸出被以下
> * STATE: INIT => CONNECT handle 0x907ef0; line 1034 (connection #-5000)
> * Added connection 0. The cache now contains 1 members
> * STATE: CONNECT => WAITRESOLVE handle 0x907ef0; line 1071 (connection #0)
> * Could not resolve host: myhost.com
> * Closing connection 0
> * The cache now contains 0 members
> * Expire cleared
在您的Ubuntu機器的主機文件中是否有'myhost.com'?還要確保Windows機器可以在curl之外解析主機(即ping) – 2015-03-02 20:34:59
是否嘗試了其他url? – 2015-03-02 20:36:26
沒有myhost.com在我的電腦外,我嘗試了其他主機google.com,example.com ...和ping可以解析myhost.com – zapredelom 2015-03-02 20:37:58