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