php curl发送headers

发表于 2019-11-19   |   分类于 php
    $url = $_SERVER['QUERY_STRING']; 
    $headers = array('Connection: keep-alive');
    $user_agent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
    $curl = curl_init(); // 启动一个CURL会话
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt ($curl, CURLOPT_REFERER, 'https://www.baidu.com/');
    curl_setopt($curl, CURLOPT_USERAGENT, $user_agent); // 模拟用户使用的浏览器  
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);  // 从证书中检查SSL加密算法是否存在
    $data = curl_exec($curl);
    curl_close($curl);
    echo $data;
© 2020 Powered by Typecho & Theme Quark