//{HTTPS域名}:443:{IP地址} NSString *curlHost = ...; _hosts_list = curl_slist_append(_hosts_list, curlHost.UTF8String); curl_easy_setopt(_curl, CURLOPT_RESOLVE, _hosts_list);其中 curlHost 形如:
{HTTPS域名}:443:{IP地址}
_hosts_list 是结构体类型hosts_list,可以设置多个IP与Host之间的映射关系。curl_easy_setopt方法中传入CURLOPT_RESOLVE 将该映射设置到 HTTPS 请求中。
这样就可以达到设置SNI的目的。
我在这里写了一个 Demo:CYLCURLNetworking,里面包含了编译好的支持 IPv6 的 libcurl 包,演示了下如何通过curl来进行类似NSURLSession。
参考链接:
Apple - Communicating with HTTP Servers
Apple - HTTPS Server Trust Evaluation - Server Name Failures
Apple - HTTPS Server Trust Evaluation - Trusting One Specific Certificate
《HTTPDNS > 最佳实践 > HTTPS(含SNI)业务场景“IP直连”方案说明 HTTPS(含SNI)业务场景“IP直连”方案说明》
《在 curl 中使用指定 ip 来进行请求 https》
支持SNI与WebView的 alicloud-ios-demo
《SNI: 实现多域名虚拟主机的SSL/TLS认证》
补充说明
注意以上讨论不涉及 WKWebView 中拦截 NSURLSession 请求的 body 丢失问题。
文中提到的几个概念:
文中部分提到的域名,如果没有特殊说明均指的是 FQDN。
原文链接
阅读更多干货好文,请关注扫描以下二维码: