curl在7.46.0版本中添加了一个新的属性:CURLOPT_CONNECT_TO,可以设置host对应的ip地址和端口,而不用去手工修改系统的host配置。
php语言,从php7.0.7版本开始支持此项功能。
php示例(使用guzzlehttp):
$options = array(
'curl' => array(
CURLOPT_CONNECT_TO => ["{$baiduhost}:80:{$realhost}:80"],
),
);
$client = new \GuzzleHttp\Client($options);