利用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 相关文章推荐
怎样在UNIX系统下安装MySQL
Oct 09 PHP
PHP的可变变量名的使用方法分享
Feb 05 PHP
ajax在joomla中的原生态应用代码
Jul 19 PHP
thinkphp3.0 模板中函数的使用
Nov 13 PHP
使用php转义输出HTML到JavaScript
Mar 27 PHP
PHP使用stream_context_create()模拟POST/GET请求的方法
Apr 02 PHP
php用户登录之cookie信息安全分析
May 13 PHP
php+ajax注册实时验证功能
Jul 20 PHP
24条货真价实的PHP代码优化技巧
Jul 28 PHP
PHP获取文本框、密码域、按钮的值实例代码
Apr 19 PHP
弹出模态框modal的实现方法及实例
Sep 19 PHP
Laravel 框架控制器 Controller原理与用法实例分析
Apr 14 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
我的论坛源代码(三)
2006/10/09 PHP
php新建文件的方法实例
2019/09/26 PHP
php使用redis的几种常见操作方式和用法示例
2020/02/20 PHP
js 自定义的联动下拉框
2010/02/07 Javascript
基于jquery自定义的漂亮单选按钮RadioButton
2013/11/19 Javascript
jquery新的绑定事件机制on方法的使用方法
2014/04/15 Javascript
JavaScript中操作字符串小结
2015/05/04 Javascript
javascript实现可拖动变色并关闭层窗口实例
2015/05/15 Javascript
JavaScript forEach()遍历函数使用及介绍
2015/07/08 Javascript
深入浅析JavaScript中prototype和proto的关系
2015/11/15 Javascript
JavaScript核心语法总结(推荐)
2016/06/02 Javascript
JavaScript 身份证号有效验证详解及实例代码
2016/10/20 Javascript
jquery+Jscex打造游戏力度条
2020/09/12 Javascript
SpringMVC简单整合Angular2的示例
2017/07/31 Javascript
React Native 截屏组件的示例代码
2017/12/06 Javascript
微信小程序自定义toast的实现代码
2018/11/16 Javascript
在vue中获取微信支付code及code被占用问题的解决方法
2019/04/16 Javascript
vue.js 输入框输入值自动过滤特殊字符替换中问标点操作
2020/08/31 Javascript
Vue 3自定义指令开发的相关总结
2021/01/29 Vue.js
[02:53]DOTA2英雄昆卡基础教程
2013/11/25 DOTA
Python批量更改文件名的实现方法
2017/10/29 Python
flask中使用蓝图将路由分开写在不同文件实例解析
2018/01/19 Python
Python openpyxl 遍历所有sheet 查找特定字符串的方法
2018/12/10 Python
Python 把序列转换为元组的函数tuple方法
2019/06/27 Python
Brydge英国:适用于Apple iPad和Microsoft Surface Pro的蓝牙键盘
2019/05/16 全球购物
韩国最大的购物网站:Gmarket
2019/06/20 全球购物
Sahajan美国:阿育吠陀护肤品牌
2021/01/09 全球购物
演讲稿开场白
2014/01/13 职场文书
英文商务邀请信
2014/01/22 职场文书
小学英语教学反思案例
2014/02/04 职场文书
人力资源总监工作说明
2014/03/03 职场文书
社区志愿者培训方案
2014/06/10 职场文书
报名委托书
2015/01/29 职场文书
护理专业自我评价
2015/03/11 职场文书
2015年三万活动总结
2015/03/25 职场文书
五星红旗迎风飘扬观后感
2015/06/17 职场文书