PHP CURL提交参数

    //CURL GET方式传参
    function get_curl($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $output=curl_exec($ch);
    print_r($output);
    echo "<br>";
    $out_array = json_decode($output,true);
    curl_close($ch);
    return $out_array;
    }
    //CURL  GET方式传参

    //CURL JSON方式传参
    function json_curl($url,$post_data) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $output = curl_exec($ch);
    print_r($output);
    echo "<br>";
    $out_array = json_decode($output,true);
    curl_close($ch);
    //echo $output."<br><br>";
    return $out_array;
    }
    //CURL JSON方式传参

    //CURL POST方式传参
    function post_curl($url,$post_data) {
    $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_POST, 1);
    $post_data = array(
    "userid" => "$zhangsan",
    "name" => "张三"
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $output = curl_exec($ch);
    curl_close($ch);
    $out_array = json_decode($output,true);
    return $out_array;
    }
    //CURL POST方式传参

    转载请注明:RAIN MAN » PHP CURL提交参数

    喜欢 0
标签: , ,

还没有人抢沙发呢~