利用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 相关文章推荐
通过PHP CLI实现简单的数据库实时监控调度
Jul 01 PHP
php+mysql 实现身份验证代码
Mar 24 PHP
php实现utf-8和GB2312编码相互转换函数代码
Feb 07 PHP
PHP数据库链接类(PDO+Access)实例分享
Dec 05 PHP
php获取YouTube视频信息的方法
Feb 11 PHP
php限制ip地址范围的方法
Mar 31 PHP
Smarty使用自定义资源的方法
Aug 08 PHP
php版微信小店调用api示例代码
Nov 12 PHP
PHP 类与构造函数解析
Feb 06 PHP
php修改数组键名的方法示例
Apr 15 PHP
PHP的mysqli_stat()函数讲解
Jan 23 PHP
php swoole多进程/多线程用法示例【基于php7nts版】
Aug 12 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
php4的session功能评述(一)
2006/10/09 PHP
ThinkPHP自动验证失败的解决方法
2011/06/09 PHP
php数字游戏 计算24算法
2012/06/10 PHP
基于php设计模式中单例模式的应用分析
2013/05/15 PHP
PHP中curl_setopt函数用法实例分析
2015/04/16 PHP
对比PHP对MySQL的缓冲查询和无缓冲查询
2016/07/01 PHP
PHP实现无限分类的实现方法
2016/11/14 PHP
CI框架附属类用法分析
2018/12/26 PHP
Javascript的IE和Firefox兼容性汇编
2006/07/01 Javascript
jquery 防止表单重复提交代码
2010/01/21 Javascript
Table冻结表头示例代码
2013/08/20 Javascript
jQuery Mobile的loading对话框显示/隐藏方法分享
2013/11/26 Javascript
js清除input中type等于file的值域(示例代码)
2013/12/24 Javascript
nodejs命令行参数处理模块commander使用实例
2014/09/17 NodeJs
关于JS中setTimeout()无法调用带参函数问题的解决方法
2016/06/21 Javascript
JavaScript兼容浏览器FF/IE技巧
2016/08/14 Javascript
Angularjs验证用户输入的字符串是否为日期时间
2017/06/01 Javascript
js回文数的4种判断方法示例
2019/06/04 Javascript
vue-cli随机生成port源码的方法
2019/09/02 Javascript
javascript实现函数柯里化与反柯里化过程解析
2019/10/08 Javascript
python中wx将图标显示在右下角的脚本代码
2013/03/08 Python
Python匹配中文的正则表达式
2016/05/11 Python
Python面向对象编程基础解析(二)
2017/10/26 Python
使用Python通过win32 COM实现Word文档的写入与保存方法
2018/05/08 Python
Python列表推导式与生成器用法分析
2018/08/02 Python
python 运用Django 开发后台接口的实例
2018/12/11 Python
Django ManyToManyField 跨越中间表查询的方法
2018/12/18 Python
Python中turtle库的使用实例
2019/09/09 Python
python返回数组的索引实例
2019/11/28 Python
python能在浏览器能运行吗
2020/06/17 Python
瑞典度假品牌:OAS
2019/05/28 全球购物
办公室文员工作自我评价
2013/12/01 职场文书
我的教育故事演讲稿
2014/05/04 职场文书
幼儿园优秀班主任事迹材料
2014/05/14 职场文书
求职意向书
2014/07/29 职场文书
Redis三种集群模式详解
2021/10/05 Redis