码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-09-18 11:18:43      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:http   io   os   ar   sp   cti   on   c   ad   

$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;
}

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

标签:http   io   os   ar   sp   cti   on   c   ad   

原文地址:http://www.cnblogs.com/ymms/p/3978605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!