cURL - 使用post發送數據


function post($url, $data) {
    
    //初使化init方法
    $ch = curl_init();

    //指定URL
    curl_setopt($ch, CURLOPT_URL, $url);

    //設定請求后返回結果
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    //聲明使用POST方式來進行發送
    curl_setopt($ch, CURLOPT_POST, 1);

    //發送什么數據呢
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

    
    //忽略證書
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

    //忽略header頭信息
    curl_setopt($ch, CURLOPT_HEADER, 0);

    //設置超時時間
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    //發送請求
    $output = curl_exec($ch);

    //關閉curl
    curl_close($ch);

    //返回數據
    return $output;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM