PHP CURL header 设置HOST主机头进行访问并 POST提交數據

$host = array("Host: act.qzone.qq.com");// 域名不帶http://
$data = array(
            ‘aa‘ => ‘xx‘,
            ‘bb‘=>‘xx‘
        );     
$url = ‘http://127.0.0.1/xxx/xxx/api/‘;
var_dump( $this->curl_post($host, $data,$url) );


function curl_post($host,$data,$url)
{
   $ch = curl_init();
   $res= curl_setopt ($ch, CURLOPT_URL,$url);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt ($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch,CURLOPT_HTTPHEADER,$host);
   $handles = curl_exec($ch);
   curl_close($ch);
   return $handles;
}
function postData($url, $post)
{
    $ch = curl_init();
    $timeout = 300;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $handles = curl_exec($ch);
    curl_close($ch);
    return $handles;
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。