ios - iOS中如何不编辑/etc/hosts直接ip访问HTTPS?

标签 ios objective-c dns afnetworking

默认情况下,example.com 解析为 123.123.123.123

但是如果我希望它被解析为 100.100.100.100

对于 http,我可以简单地将 url 更改为 http://100.100.100.100,标题为“Host: example.com”。

但它不适用于 HTTPS。(错误:SSL 证书问题:无效的证书链)。

我的问题是不是为什么,我不想跳过证书验证。

如何在 Objective-C 中获得与 curl 相同的效果

--resolve 选项:

--resolve <host:port:address>
          Provide a custom address for a specific host and port pair. Using this, you can make the  curl  requests(s)
          use  a specified address and prevent the otherwise normally resolved address to be used. Consider it a sort
          of /etc/hosts alternative provided on the command line. The port number should be the number used  for  the
          specific  protocol  the  host  will  be  used for. It means you need several entries if you want to provide
          address for the same host but different ports.

换句话说,如何在 Objective-C 的 HTTPS 请求中进行自定义 DNS 查询?

最佳答案

当您使用 https 时,您在请求中使用的地址与服务器返回的证书给您的地址必须一致。

如果您向 https://100.100.100.100 发送请求那么服务器必须返回 100.100.100.100 的证书。即使您成功连接到 https://www.xyz.com,并且 www.xyz.com 解析为 100.100.100.100,连接到 https://100.100.100.100不会工作,不能工作,绝对不能工作,因为服务器将返回 www.xyz.com 而不是 100.100.100.100 的证书。

关于ios - iOS中如何不编辑/etc/hosts直接ip访问HTTPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32179688/

相关文章:

ios - Urban Airship 在调用起飞时坠毁

ios - 使用 URLSeason 连接 github

ios - 在iOS上获取软键盘以显示在Pure AS3移动项目中(flex 4.5)

objective-c - 将索引转换为坐标的算术仅返回索引

ios - 如何解决 Apple Match-O 链接器错误?

amazon-web-services - 如何设置 RDF4J 工作台的默认服务器?

c - 为什么 gethostbyname() 在不存在的主机名上不会失败?

java - Swift 中的高级 Java 枚举

iphone - 如何使用节标题在 UITableViewController 中调整 UITableView 的大小

python - 告诉 urllib2 使用自定义 DNS