curl选项中的CURLOPT_DNS_SERVERS和CURLOPT_DNS_LOCAL_IP4之间有什么不同



下面两个代码的具体区别是什么?

CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
curl_easy_setopt(curl, CURLOPT_DNS_SERVERS, "192.168.0.100");
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
curl_easy_setopt(curl, CURLOPT_DNS_LOCAL_IP4, "192.168.0.100");
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}

主要是与CURLOPT_DNS_SERVERSCURLOPT_DNS_LOCAL_IP4有关的问题。

比较https://curl.se/libcurl/c/CURLOPT_DNS_SERVERS.html和https://curl.se/libcurl/c/CURLOPT_DNS_LOCAL_IP4.html看区别,主要是:

  • "传递一个char*,它是要使用的DNS服务器的列表;对于CURLOPT_DNS_SERVERS
  • "设置解析器应该绑定到的本地IPv4地址;对于CURLOPT_DNS_LOCAL_IP4

第二种情况应该很少需要,它强制为任何传出的DNS查询指定一个特定的本地IPv4地址(如果框中有多个(。

第一个选项设置要联系的服务器。

最新更新