029-81773686

宏 · 新闻

当前位置: 首页 > 宏 · 新闻宏博观点  

号外!西安建站公司经验分享之-POST方式如何实现(推荐)

2020.07.22

西安建站公司经验分享之-小博教你如何实现POST方式(推荐)

function postData($url,$data){

    $ch = curl_init();

    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($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 curl_error($ch);

    }

    curl_close($ch);

    return $tmpInfo;

}



GET方式实现


function getData($url){

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,$url);

    curl_setopt($ch, CURLOPT_HEADER,0);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//禁止调用时就输出获取到的数据

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);

    $result = curl_exec($ch);

    curl_close($ch);

    return $result;

}


精彩案例

让价值共享 记录企业发展脚步 感恩相伴 029-81773686   18966895139