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


Posted in PHP onSeptember 22, 2015

使用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);
  $<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);
  $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;
  }
  //$<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";
  $head = "GET ".$info['path']."?".$query_str." HTTP/.\r\n";
  $head .= "Host: ".$info['host']."\r\n";
  $head .= "\r\n";
  $write = fputs($fp,$head);
  while(!feof($fp)){
    $<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,);
    echo $line;
  }
  fclose($fp);
  return true;
}
//fsockopen模拟POST
function sock_post($url,$<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()){
  $query = http_build_query($data); 
  $info = parse_url($url);
  $fp = fsockopen($info["host"], , $errno, $errstr, );
  $head = "POST ".$info['path']."?".$info["query"]." HTTP/.\r\n";
  $head .= "Host: ".$info['host']."\r\n";
  $head .= "Referer: http://".$info['host'].$info['path']."\r\n";
  $head .= "Content-type: application/x-www-form-urlencoded\r\n";
  $head .= "Content-Length: ".strlen(trim($query))."\r\n";
  $head .= "\r\n";
  $head .= trim($query);
  $write = fputs($fp, $head);
  while (!feof($fp))
  {
    $line = fread($fp,);
    echo $line;
  }
}

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

PHP 相关文章推荐
支持数组的ADDSLASHES的php函数
Feb 16 PHP
PHP显示今天、今月、上月、今年的起点/终点时间戳的代码
May 25 PHP
在Ubuntu 14.04上部署 PHP 环境及 WordPress
Sep 02 PHP
PHP加密解密字符串汇总
Apr 26 PHP
PHP中file_get_contents函数抓取https地址出错的解决方法(两种方法)
Sep 22 PHP
PHP中Session和Cookie是如何操作的
Oct 10 PHP
PHP判断FORM表单或URL参数来的数据是否为整数的方法
Mar 25 PHP
PHP实现163邮箱自动发送邮件
Mar 29 PHP
PHP随机数 C扩展随机数
May 04 PHP
功能强大的php分页函数
Jul 20 PHP
PHP序列化操作方法分析
Sep 28 PHP
YII2框架使用控制台命令的方法分析
Mar 18 PHP
PHP判断字符串长度的两种方法很实用
Sep 22 #PHP
PHP中file_get_contents函数抓取https地址出错的解决方法(两种方法)
Sep 22 #PHP
浅析PHP关键词替换的类(避免重复替换,保留与还原原始链接)
Sep 22 #PHP
PHP实现搜索相似图片
Sep 22 #PHP
从刷票了解获得客户端IP的方法
Sep 21 #PHP
fsockopen pfsockopen函数被禁用,SMTP发送邮件不正常的解决方法
Sep 20 #PHP
分享ThinkPHP3.2中关联查询解决思路
Sep 20 #PHP
You might like
PHP中的类-什么叫类
2006/11/20 PHP
生成静态页面的PHP类
2006/11/25 PHP
PHP5.2中date()函数显示时间与北京时间相差8小时的解决办法
2009/05/28 PHP
php fsockopen伪造post与get方法的详解
2013/06/14 PHP
基于递归实现的php树形菜单代码
2014/11/19 PHP
PHP多维数组遍历方法(2种实现方法)
2015/12/10 PHP
php获取当前url地址的方法小结
2017/01/10 PHP
Prototype 1.5.0_rc1 及 Prototype 1.5.0 Pre0小抄本
2006/09/22 Javascript
javascript AutoScroller 函数类
2009/05/29 Javascript
EXTJS记事本 当CompositeField遇上RowEditor
2011/07/31 Javascript
jQuery实现级联下拉框实战(5)
2017/02/08 Javascript
bootstrap table实现单击单元格可编辑功能
2017/03/28 Javascript
react中的ajax封装实例详解
2017/10/17 Javascript
vue实现重置表单信息为空的方法
2018/09/29 Javascript
VeeValidate 的使用场景以及配置详解
2019/01/11 Javascript
Nodejs中的require函数的具体使用方法
2019/04/02 NodeJs
iview的table组件自带的过滤器实现
2019/07/12 Javascript
Vue发布订阅模式实现过程图解
2020/04/30 Javascript
详解js中的几种常用设计模式
2020/07/16 Javascript
[04:37]DOTA2英雄梦之声Vol20发条
2014/06/20 DOTA
[57:28]2018DOTA2亚洲邀请赛 4.6 淘汰赛 TNC vs Liquid 第一场
2018/04/10 DOTA
Python中的__new__与__init__魔术方法理解笔记
2014/11/08 Python
python selenium执行所有测试用例并生成报告的方法
2019/02/13 Python
Python3使用TCP编写一个简易的文件下载器功能
2019/05/08 Python
python队列Queue的详解
2019/05/10 Python
Python使用正则表达式分割字符串的实现方法
2019/07/16 Python
Python集合基本概念与相关操作实例分析
2019/10/30 Python
Python selenium使用autoIT上传附件过程详解
2020/05/26 Python
Python 解决相对路径问题:&quot;No such file or directory&quot;
2020/06/05 Python
python中的时区问题
2021/01/14 Python
IE滤镜与CSS3效果(详细整理分享)
2013/01/25 HTML / CSS
在购买印度民族服饰:Soch
2020/09/15 全球购物
大专生自我鉴定怎么写
2014/09/16 职场文书
南京导游词
2015/02/03 职场文书
90条交通安全宣传标语
2019/10/12 职场文书
Nginx报错104:Connection reset by peer问题的解决及分析
2022/07/23 Servers