【发布时间】:2015-08-24 10:09:35
【问题描述】:
默认情况下,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 查询?
【问题讨论】:
-
你正在尝试做的事情对我来说似乎是错误的。如果您知道要使用的 IP 地址并且它们是真实的,那么使用这些 IP 运行的设备也有名称。让我们假设 192.168.0.1 是 one.example.com,而 192.168.0.2 是 two.example.com。然后,与其尝试规避名称解析 IP 映射,不如将域 example.com 的代码中的映射添加到您要在测试中使用的真实设备名称。或者在某个地方有一个知道使用哪个变量的变量:one.example.com 或 two.example.com。从这个问题来看,您必须有计划将代码切换到 .0.2 吗?
-
@RoryMcKinnel 一种可能的用例是绕过 ISP 提供商造成的 DNS 污染。
-
不确定什么是 DNS 污染?您的意思是住宅 ISP IP 地址一直在更改,因此您无法查找它们吗?如果是这样,那就是静态 ISP IP 的用途,或者动态 DNS 用于具有动态 IP 的人想要一个固定的 DNS 查找名称。无论哪种方式,如果您需要覆盖,那么对我来说,您需要自己的映射,因为您暗示您知道要使用的映射而不是 DNS 系统?所以你想要一个函数
createURLFromDNSNameUsingMyDNSOverrides之类的。 -
-
@RoryMcKinnel 例如,server.com 的正确 ip 是 123.123.123.123。但是某些最终用户可能会得到错误的 dns 结果,在这种情况下,由于 ip 错误,他们无法连接到 server.com。是的。我知道映射。 DNS有时是错误的。 en.wikipedia.org/wiki/DNS_spoofingen.greatfire.org/faq/what-does-dns-poisoning-mean
标签: ios objective-c dns afnetworking