防止cURL将主机解析为IP

时间:2015-08-02 03:20:15

标签: curl

为了节省时间,我想定义什么ip从什么主机解析,所以curl不必浪费时间自己这样做(IP将是静态的)

我只是希望那些经验丰富的人确认我正在这样做的方式实际上会阻止curl尝试解析IP:

curl_easy_setopt(curl, CURLOPT_URL, "https://xxx.xxx.xxx.xxx");
struct curl_slist* chunk = NULL;
chunk = curl_slist_append(chunk,"Host: website.com"); //(the website doesn't respond correctly if the host is not set)
std::string curl_hosts = "website.com:443:xxx.xxx.xxx.xxx";
std::string curl_hosts80 = "website.com:80:xxx.xxx.xxx.xxx";
host = curl_slist_append(host,curl_hosts.c_str());
host = curl_slist_append(host,curl_hosts80.c_str());
curl_easy_setopt(curl, CURLOPT_RESOLVE, host);

感谢。

1 个答案:

答案 0 :(得分:1)

将主机/ IP添加到/etc/hosts文件