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

php發(fā)送post請求的三種方法

復(fù)制代碼 代碼如下:
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技術(shù)php發(fā)送post請求的三種方法,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 竹溪县| 彰武县| 绿春县| 徐汇区| 汝城县| 若羌县| 衡南县| 隆化县| 盐城市| 七台河市| 和平县| 内黄县| 马鞍山市| 土默特左旗| 南乐县| 宣威市| 芦溪县| 那坡县| 龙川县| 芦山县| 九龙县| 吉木乃县| 江门市| 墨脱县| 德令哈市| 苗栗市| 宣武区| 高台县| 黄浦区| 新津县| 石狮市| 通化县| 图木舒克市| 夏河县| 吐鲁番市| 长兴县| 福安市| 成安县| 灵丘县| 鹤岗市| 中牟县|