功能強大的PHP POST提交數(shù)據(jù)類
來源:易賢網(wǎng) 閱讀:908 次 日期:2016-08-13 13:37:30
溫馨提示:易賢網(wǎng)小編為您整理了“功能強大的PHP POST提交數(shù)據(jù)類”,方便廣大網(wǎng)友查閱!

這篇文章主要為大家詳細介紹了功能強大的PHP POST提交數(shù)據(jù)類,代碼簡潔且具有一定的參考價值,感興趣的小伙伴們可以參考一下

<?php 

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;

  }

}

?>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:功能強大的PHP POST提交數(shù)據(jù)類
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)