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

首頁 > 開發(fā) > PHP > 正文

利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法

2024-05-04 23:39:06
字體:
供稿:網(wǎng)友

使用php可以模擬post和get傳送數(shù)據(jù)到別的網(wǎng)頁或者是站點(diǎn),那么怎么傳送數(shù)據(jù)呢?下面由小編給大家介紹利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法,需要的朋友一起看看吧

使用php可以模擬 post 和 get 傳送數(shù)據(jù)到別的網(wǎng)頁或站點(diǎn)

 

 
  1. $arr=array
  2. 'user'=>'test'
  3. 'password'=>'' 
  4. ); 
  5. sock_get($post_url,$arr); 
  6. sock_post($post_url,$arr);  
  7. //fsocket模擬get提交 
  8. function sock_get($url,$query=array()){ 
  9. $query_str = http_build_query($query); 
  10. #FormatTableID_0#lt;span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=&app_id=&c=news&cf=&ch=&di=&fv=&is_app=&jk=ecbeccb&k=info&k=info&kdi=&luki=&n=&p=baidu&q=_cpr&rb=&rs=&seller_id=&sid=bccbece&ssp=&stid=&t=tpclicked_hc&td=&tu=u&u=http%A%F%Fwww%Eixuexiwang%Ecom%Fphp%Dfunction%F%F%F%Ehtml&urlid=" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">info</span></a></span> = parse_url($url); 
  11. $port = isset($info['port'])? $info['port'] : ; 
  12. $query_str = emptyempty($info["query"])?$query_str:$info["query"].'&'.$query_str
  13. $fp = fsockopen($info["host"], $port$errno$errstr, ); 
  14. if(!$fp){ 
  15. return FALSE; 
  16. //#FormatTableID_0#lt;span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=&app_id=&c=news&cf=&ch=&di=&fv=&is_app=&jk=ecbeccb&k=head&k=head&kdi=&luki=&n=&p=baidu&q=_cpr&rb=&rs=&seller_id=&sid=bccbece&ssp=&stid=&t=tpclicked_hc&td=&tu=u&u=http%A%F%Fwww%Eixuexiwang%Ecom%Fphp%Dfunction%F%F%F%Ehtml&urlid=" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">head</span></a></span> = "GET ".$info['path']."?".$info["query"]." HTTP/./r/n"; 
  17. $head = "GET ".$info['path']."?".$query_str." HTTP/./r/n"
  18. $head .= "Host: ".$info['host']."/r/n"
  19. $head .= "/r/n"
  20. $write = fputs($fp,$head); 
  21. while(!feof($fp)){ 
  22. #FormatTableID_0#lt;span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=&app_id=&c=news&cf=&ch=&di=&fv=&is_app=&jk=ecbeccb&k=line&k=line&kdi=&luki=&n=&p=baidu&q=_cpr&rb=&rs=&seller_id=&sid=bccbece&ssp=&stid=&t=tpclicked_hc&td=&tu=u&u=http%A%F%Fwww%Eixuexiwang%Ecom%Fphp%Dfunction%F%F%F%Ehtml&urlid=" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">line</span></a></span> = fread($fp,); 
  23. echo $line
  24. fclose($fp); 
  25. return true; 
  26. //fsockopen模擬POST 
  27. function sock_post($url,#FormatTableID_0#lt;span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=&app_id=&c=news&cf=&ch=&di=&fv=&is_app=&jk=ecbeccb&k=data&k=data&kdi=&luki=&n=&p=baidu&q=_cpr&rb=&rs=&seller_id=&sid=bccbece&ssp=&stid=&t=tpclicked_hc&td=&tu=u&u=http%A%F%Fwww%Eixuexiwang%Ecom%Fphp%Dfunction%F%F%F%Ehtml&urlid=" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">data</span></a></span>=array()){ 
  28. $query = http_build_query($data);  
  29. $info = parse_url($url); 
  30. $fp = fsockopen($info["host"], , $errno$errstr, ); 
  31. $head = "POST ".$info['path']."?".$info["query"]." HTTP/./r/n"
  32. $head .= "Host: ".$info['host']."/r/n"
  33. $head .= "Referer: http://".$info['host'].$info['path']."/r/n"
  34. $head .= "Content-type: application/x-www-form-urlencoded/r/n"
  35. $head .= "Content-Length: ".strlen(trim($query))."/r/n"
  36. $head .= "/r/n"
  37. $head .= trim($query); 
  38. $write = fputs($fp$head); 
  39. while (!feof($fp)) 
  40. $line = fread($fp,); 
  41. echo $line

以上內(nèi)容是給大家分享的利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法,希望大家能夠喜歡,更多有關(guān)php fsockopen知識請持續(xù)關(guān)注本站,謝謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 定日县| 阜阳市| 张家港市| 桦川县| 金华市| 绍兴市| 康平县| 德州市| 东城区| 周宁县| 扬中市| 平安县| 大兴区| 腾冲县| 彭州市| 诸城市| 长春市| 斗六市| 宜宾市| 勃利县| 从化市| 台东市| 武城县| 沙洋县| 阿拉善右旗| 库尔勒市| 茂名市| 巩留县| 克什克腾旗| 吉水县| 雅江县| 雅安市| 潜山县| 朝阳区| 名山县| 满洲里市| 剑河县| 调兵山市| 余姚市| 东丰县| 江华|