默认情况下,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/