色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php發送post請求的三種方法

復制代碼 代碼如下:
class Request{

    public static function post($url, $post_data = '', $timeout = 5){//curl

        $ch = curl_init();

        curl_setopt ($ch, CURLOPT_URL, $url);

        curl_setopt ($ch, CURLOPT_POST, 1);

        if($post_data != ''){

            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

        }

        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

        curl_setopt($ch, CURLOPT_HEADER, false);

        $file_contents = curl_exec($ch);

        curl_close($ch);

        return $file_contents;

    }


    public static function post2($url, $data){//file_get_content

       

        $postdata = http_build_query(

            $data

        );

       

        $opts = array('http' =>

                      array(

                          'method'  => 'POST',

                          'header'  => 'Content-type: application/x-www-form-urlencoded',

                          'content' => $postdata

                      )

        );

       

        $context = stream_context_create($opts);


        $result = file_get_contents($url, false, $context);

        return $result;


    }


    public static function post3($host,$path,$query,$others=''){//fsocket


        $post="POST $path HTTP/1.1/r/nHost: $host/r/n";

        $post.="Content-type: application/x-www-form-";

        $post.="urlencoded/r/n${others}";

        $post.="User-Agent: Mozilla 4.0/r/nContent-length: ";

        $post.=strlen($query)."/r/nConnection: close/r/n/r/n$query";

        $h=fsockopen($host,80);

        fwrite($h,$post);

        for($a=0,$r='';!$a;){

                $b=fread($h,8192);

                $r.=$b;

                $a=(($b=='')?1:0);

            }

        fclose($h);

        return $r;

    }
}

php技術php發送post請求的三種方法,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 方山县| 饶河县| 湖口县| 云梦县| 博爱县| 高雄市| 葵青区| 龙岩市| 建宁县| 长治县| 柳林县| 华宁县| 芦山县| 北流市| 冀州市| 靖西县| 沂源县| 石柱| 余庆县| 酒泉市| 汉源县| 甘孜| 南和县| 什邡市| 泾川县| 榕江县| 志丹县| 永康市| 依兰县| 巴楚县| 明溪县| 宾川县| 华坪县| 苏尼特右旗| 兴安盟| 宿松县| 秭归县| 扶沟县| 庆城县| 井冈山市| 琼结县|