色尼玛亚洲综合影院,亚洲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)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 内丘县| 宁远县| 司法| 海门市| 恩施市| 开鲁县| 兴海县| 滦南县| 云阳县| 台南县| 延安市| 华池县| 舟曲县| 五寨县| 天等县| 鹤山市| 海安县| 贵定县| 克什克腾旗| 阿鲁科尔沁旗| 宁阳县| 马关县| 北票市| 漠河县| 瑞金市| 子洲县| 宁强县| 临洮县| 西林县| 湘阴县| 尉氏县| 香河县| 迭部县| 宜丰县| SHOW| 绵阳市| 阿克陶县| 两当县| 金山区| 开封县| 安西县|