栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

利用PHP fsockopen 模拟POST/GET传送数据的方法

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

利用PHP fsockopen 模拟POST/GET传送数据的方法

使用php可以模拟 post 和 get 传送数据到别的网页或站点

$arr=array(
  'user'=>'test',
  'password'=>''
);
sock_get($post_url,$arr);
sock_post($post_url,$arr); 
//fsocket模拟get提交
function sock_get($url,$query=array()){
  $query_str = http_build_query($query);
  $info = parse_url($url);
  $port = isset($info['port'])? $info['port'] : ;
  $query_str = empty($info["query"])?$query_str:$info["query"].'&'.$query_str;
  $fp = fsockopen($info["host"], $port, $errno, $errstr, );
  if(!$fp){
    return FALSE;
  }
  //$head = "GET ".$info['path']."?".$info["query"]." HTTP/.rn";
  $head = "GET ".$info['path']."?".$query_str." HTTP/.rn";
  $head .= "Host: ".$info['host']."rn";
  $head .= "rn";
  $write = fputs($fp,$head);
  while(!feof($fp)){
    $line = fread($fp,);
    echo $line;
  }
  fclose($fp);
  return true;
}
//fsockopen模拟POST
function sock_post($url,$data=array()){
  $query = http_build_query($data); 
  $info = parse_url($url);
  $fp = fsockopen($info["host"], , $errno, $errstr, );
  $head = "POST ".$info['path']."?".$info["query"]." HTTP/.rn";
  $head .= "Host: ".$info['host']."rn";
  $head .= "Referer: http://".$info['host'].$info['path']."rn";
  $head .= "Content-type: application/x-www-form-urlencodedrn";
  $head .= "Content-Length: ".strlen(trim($query))."rn";
  $head .= "rn";
  $head .= trim($query);
  $write = fputs($fp, $head);
  while (!feof($fp))
  {
    $line = fread($fp,);
    echo $line;
  }
}

以上内容是给大家分享的利用PHP fsockopen 模拟POST/GET传送数据的方法,希望大家能够喜欢,更多有关php fsockopen知识请持续关注本站,谢谢。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/44753.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号