[PHP代码] php模拟post发送数据
2016-03-22 17:14
731 查看
<?PHP $flag = 0; //要post的数据 $argv = array( 'var1'=>'abc', 'var2'=>'你好吗'); //构造post字符串 foreach ($argv as $key=>$value) { if ($flag!=0) { $params .= "&"; $flag = 1; }http://www.kmrlyy.com/btrl/33485.html $params.= $key."="; $params.= urlencode($value); $flag = 1; }http://www.kmrlyy.com/penqiangyan/33486.html $length = strlen($params); //创建socket连接 $fp = fsockopen("127.0.0.1",80,$errno,$errstr,10) or exit($errstr."--->".$errno); //构造post请求的头 $header = "POST /mobile/try.php HTTP/1.1"; $header .= "Host:127.0.0.1"; $header .= "Referer:/mobile/sendpost.php"; $header .= "Content-Type: application/x-www-form-urlencoded"; $header .= "Content-Length: ".$length.""; $header .= "Connection: Close";http://www.kmrlyy.com/gongjingmilan/33487.html //添加post的字符串 $header .= $params.""; //发送post的数据 fputs($fp,$header); $inheader = 1; while (!feof($fp)) { $line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据 if ($inheader && ($line == "n" || $line == "")) { $inheader = 0; }http://www.kmrlyy.com/rlzjsj/33488.html if ($inheader == 0) { echo $line; }http://www.kmrlyy.com/gongjingxirou/33489.html }www.kmrlyy.com fclose($fp); ?> |
相关文章推荐
- [PHP代码] 用php的fsocket模拟get提交 模拟post提交表单
- FPGA静态时序分析——IO口时序(Input Delay /output Delay)(转载)
- 自定义ContentProvider
- 韩顺平老师讲诉如何学习PHP
- 韩顺平老师讲诉如何学习PHP
- php的预定义数组
- 1.1.4 A+B for Input-Output Practice (V)
- A+B for Input-Output Practice (IV)
- 1.1.3 A+B for Input-Output Practice (III)
- Ubuntu Webstorm/PhpStorm创建桌面快捷启动和菜单文字变粗解决
- phpstudy2016最新版本mysql无法使用innodb的问题解决
- php中将数据加入到文件中
- php判断键值在数组中是否存在
- PHP获取多个checkbox的值
- PHP转换SQLite数据库为MySQL
- thinkphp-许愿墙-3
- 数据条数过大时,分片采集
- Zend加密服务器配置以及加密工具的使用
- PHP快速排序
- PHP二分查找