问题描述
Curl具有手动指定要解析主机的IP的功能。例如:
Curl has a feature for manually specifying which IP to resolve a host to. For example:
curl https://www.google.com --resolve "www.google.com:443:173.194.72.112"
这在使用HTTPS时特别有用。如果它只是一个HTTP请求,我可以通过直接指定IP地址并添加主机头来实现相同的目的。但是在HTTPS中会破坏连接,因为SSL证书主机会与IP地址而不是主机头进行比较。
This is especially useful when using HTTPS. If it was just a HTTP request, I could have achieved the same by specifying the IP address directly, and adding a host header. But in HTTPS that would break the connection since the SSL certificate host would be compared to the IP address and not the host header.
我的问题是,我怎么能这样做在PHP中同样的事情?
My question is, how can I do the same thing in PHP?
推荐答案
根据,在5.5.0中添加了对 CURLOPT_RESOLVE
的支持。
请注意,在撰写本文时,它尚未记录,但根据它以数组作为参数。
According to the changelog, support for CURLOPT_RESOLVE
was added in 5.5.0.
Note that at the time of writing it's not even documented yet, but according to this bug report it takes an array as argument.
这篇关于如何在PHP中手动解析HTTP(S)连接中的主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!