如何在不编辑iOS中的/ etc/hosts的情况下使用直接ip访问HTTPS?

fre*_*ler 6 dns objective-c ios 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.
Run Code Online (Sandbox Code Playgroud)

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

gna*_*729 2

当您使用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 的证书。