使用file_get_contents提交http post
来源:互联网 发布:淘宝联盟官网下载 编辑:程序博客网 时间:2024/05/04 17:12
使用file_get_contents提交http post时需开启了allow_url_fopen。
1.先看一下目标网页(假设是http://localhost/response.php)
response.php
<?php echo "<pre>"; print_r($_POST); print_r($_COOKIE); ?>
本文讲述的只是http post请求的发送,所以,目标页只是回显所收到的post和cookie
2.请求页
request.php
<?php $data = array("name" => 'tim',"content" => 'test'); $data = http_build_query($data); $opts = array( 'http'=>array( 'method'=>"POST", 'header'=>"Content-type: application/x-www-form-urlencoded\r\n". "Content-length:".strlen($data)."\r\n" . "Cookie: foo=bar\r\n" . "\r\n", 'content' => $data, ) ); $cxContext = stream_context_create($opts); $sFile = file_get_contents("http://localhost/response.php", false, $cxContext); echo $sFile; ?>
这个文件首先使用stream_context_create()构造了一个http请求,然后使用file_get_contents发送出去,返回的结果是:
Array ( [name] => tim [content] => test ) Array ( [foo] => bar )
所以上可以看出,只要你了解http协议,完全可以使用这两个函数构造出所有正常的http请求,比如代理,断点续传等...
来源:http://blogread.cn/it/article/269?f=sinat
- 使用file_get_contents提交http post
- 使用file_get_contents提交http post
- 使用file_get_contents提交http post
- file_get_contents提交http post get
- 使用Curl、socket、file_get_contents三种方法POST提交数据
- 使用Curl、socket、file_get_contents三种方法POST提交数据
- 使用Curl、socket、file_get_contents三种方法POST提交数据
- 使用Curl、socket、file_get_contents三种方法POST提交数据
- php用file_get_contents做post提交
- 通过Curl、socket、file_get_contents三种方法使用POST提交数据
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
- http使用Post方式进行提交数据
- C#使用post提交http请求
- http使用post方式进行提交数据
- http post提交数据
- http post提交数据
- $http.post提交示例
- http post提交数组
- Linux 监控/SNMP配置
- 第五日 高手篇:信用证全攻略
- Servlet&JSP的那些事儿(九)
- IOS Navigation总结
- commons logging与log4j配置与使用简介
- 使用file_get_contents提交http post
- myeclips8+jboss5+mysql5配置测试实体bean
- LINUX中SAMBA详细安装
- 资深软件测试工程师怎样炼成的?
- linux常用命令
- gcc gdb make makefile
- 自定义ClassLoader
- 2012CSDN年度博客之星评选http://vote.blog.csdn.net/item/blogstar/xyz_lmn
- MySql常用命令总结