1. 程式人生 > >PHP的CURL的POST/GET訪問

PHP的CURL的POST/GET訪問

cat char gen pos scrip request 5.0 -m com

本文出至:新太潮流網絡博客

/**
 * [curl以GET的方式訪問]
 * @E-mial [email protected]
 * @TIME   2017-04-07
 * @WEB    http://blog.iinu.com.cn
 * @param  [data] $url  [訪問的路徑]
 * @param  string $data [description]
 * @return [type]       [description]
 */
function curlGet($url,$data=‘‘){
    $ch = curl_init();
    $header = "Accept-Charset: utf-8";
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)‘);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $temp = curl_exec($ch);
    return $temp;
}

/**
 * [curl以POST的方式訪問]
 * @E-mial [email protected]
 * @TIME   2017-04-07
 * @WEB    http://blog.iinu.com.cn
 * @param  [data] $url  [訪問的路徑]
 * @param  [type] $data [description]
 * @return [type]       [description]
 */
function curlPost($url, $data){
    $ch = curl_init();
    $header = "Accept-Charset: utf-8";
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)‘);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $tmpInfo = curl_exec($ch);
    if (curl_errno($ch)) {
        return false;
    }else{

        return true;
    }
}

本文出至:新太潮流網絡博客

PHP的CURL的POST/GET訪問