Curl gets the solution of garbled result curlopt_encoding (Curl/post request)

Source: Internet
Author: User

//php脚本开始
/*POST请求远程内容函数*/
functionppost($url,$data,$ref){ // 模拟提交数据函数
    $curl= curl_init(); // 启动一个CURL会话
    curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址           
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER[‘HTTP_USER_AGENT‘]); // 模拟用户使用的浏览器
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
    curl_setopt($curl, CURLOPT_REFERER, $ref);
    curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
    curl_setopt($curl, CURLOPT_COOKIEFILE,$GLOBALS[‘cookie_file‘]); // 读取上面所储存的Cookie信息
    curl_setopt($curl, CURLOPT_COOKIEJAR, $GLOBALS[‘cookie_file‘]); // 存放Cookie信息的文件名称
    curl_setopt($curl, CURLOPT_HTTPHEADER,array(‘Accept-Encoding: gzip, deflate‘));
    curl_setopt($curl, CURLOPT_ENCODING, ‘gzip,deflate‘);这个是解释gzip内容.................
    curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
    curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
    $tmpInfo= curl_exec($curl); // 执行操作
    if(curl_errno($curl)) {
       echo‘Errno‘.curl_error($curl);
    }
    curl_close($curl); // 关键CURL会话
    return$tmpInfo// 返回数据

Curl gets the solution of garbled result curlopt_encoding (Curl/post request)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.