国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 元谋县| 华阴市| 伊川县| 梅州市| 白沙| 台前县| 集贤县| 海淀区| 富源县| 永宁县| 库伦旗| 余姚市| 饶阳县| 广河县| 石林| 正宁县| 卫辉市| 育儿| 五指山市| 衡南县| 麻栗坡县| 武平县| 尼玛县| 铜鼓县| 房产| 清流县| 天门市| 昌宁县| 天柱县| 武邑县| 丰县| 无锡市| 南投市| 丘北县| 沂水县| 奉贤区| 大理市| 东乡族自治县| 公主岭市| 久治县| 皮山县|