国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php實現模擬post請求用法實例

2024-05-04 23:37:43
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php實現模擬post請求用法,分析了php模擬post請求的三種常見用法,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了php實現模擬post請求的方法。分享給大家供大家參考。具體如下:

 

 
  1. class Request{ 
  2. public static function post($url, $post_data = '', $timeout = 5){//curl 
  3. $ch = curl_init();  
  4. curl_setopt ($ch, CURLOPT_URL, $url); 
  5. curl_setopt ($ch, CURLOPT_POST, 1); 
  6. if($post_data != ''){ 
  7. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
  8. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);  
  9. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
  10. curl_setopt($ch, CURLOPT_HEADER, false); 
  11. $file_contents = curl_exec($ch); 
  12. curl_close($ch); 
  13. return $file_contents; 
  14. }  
  15. public static function post2($url, $data=array()){//file_get_content 
  16. $postdata = http_build_query( 
  17. $data 
  18. );  
  19. $opts = array('http' => 
  20. array( 
  21. 'method' => 'POST'
  22. 'header' => 'Content-type: application/x-www-form-urlencoded'
  23. 'content' => $postdata 
  24. );  
  25. $context = stream_context_create($opts); 
  26. $result = file_get_contents($url, false, $context);  
  27. return $result; 
  28. }  
  29. public static function post3($host,$path,$query,$others=''){//fsocket 
  30. $post="POST $path HTTP/1.1/r/nHost: $host/r/n"
  31. $post.="Content-type: application/x-www-form-"
  32. $post.="urlencoded/r/n${others}"
  33. $post.="User-Agent: Mozilla 4.0/r/nContent-length: "
  34. $post.=strlen($query)."/r/nConnection: close/r/n/r/n$query"
  35. $h=fsockopen($host,80); 
  36. fwrite($h,$post); 
  37. for($a=0,$r='';!$a;){ 
  38. $b=fread($h,8192); 
  39. $r.=$b; 
  40. $a=(($b=='')?1:0); 
  41. fclose($h); 
  42. return $r; 
  43. $url='http://******/con/Inter.php'
  44. $data=Request::post($url,array('api'=>'tag_list')); 
  45. $data2=Request::post2($url,array('api'=>'tag_list')); 
  46. echo $data; 

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 自贡市| 西安市| 应用必备| 江都市| 福鼎市| 芜湖市| 瓦房店市| 孟州市| 揭西县| 出国| 耒阳市| 怀化市| 盘山县| 定日县| 两当县| 房山区| 和平县| 霍邱县| 博兴县| 宁津县| 库伦旗| 大余县| 揭阳市| 乌拉特后旗| 黔南| 瑞昌市| 夏河县| 芜湖市| 遵化市| 施秉县| 专栏| 宁城县| 兴化市| 双辽市| 大冶市| 永春县| 宜川县| 新安县| 乃东县| 通化市| 大新县|