socket,curl,file_get_content三种HTTP模拟表单提交的方式
来源:互联网 发布:知乎抄袭quora 编辑:程序博客网 时间:2024/06/05 11:32
了解HTTP协议,模拟表单提交
一、file_get_content模拟表单填单提交
<?php
$postData = array(
'title' => '我是file_get_contents 构造器',
'content' => "我是file_get_contents构造的数据内容",
'publish' => "发布",
);
//数据转换格式:数组生成一个经过 URL-encode 的请求字符串。
$postData = http_build_query($postData);
$ops = array(
'http' => array(
'method' => 'POST',
'header' => 'Host:localhost\r\n' .
"Content-type:application/-form-urlencoded\r\n" .
"Content-length:" . strlen($postData) ."\r\n",
'content' => $postData,
)
);
//数据转换,写入文件(文件流)
$context = stream_context_create($osp);
// file_get_contents("http://localhost/http/post.php",false,$context);
$fp = fopen("http://localhost/http/post.php", 'r', false, $context);
fclose($fp);
二、curl模拟表单提交:
注意:此处需要开启curl拓展(php.ini文件)
$url ="";
$data = array();
//初始化一个curl会话‘
$ch = curl_init();
//设置相应的会话选项
//设置提交路径
curl_setopt($ch,CURLOPT_URL,$url);
//设置提交方式
curl_setopt($ch,CURLOPT_POST,1);
//设置数据提交
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
//数据提交成功后,把数据返回为字符串
curl_setopt($ch,CURLOPT_RETURNTRANSFER,$data);
//执行并获取结果
curl_multi_exec($ch);
//释放cURL句柄
curl_close($ch);
三、socket模拟表单提交
- socket,curl,file_get_content三种HTTP模拟表单提交的方式
- PHP发送POST请求的三种方式 分别使用curl file_get_content fsocket 来实现post提交数据
- PHP发送POST请求的三种方式 分别使用curl file_get_content fsocket 来实现post提交数据
- http模拟post提交数据(三),curl方式
- php http post 方式有curl 、 file_get_content 、 fsocket ,来post提交数据
- 第四节 curl和socket方式提交表单
- 表单提交的三种方式
- js表单提交的三种方式
- 表单的三种提交方式
- 表单提交的 三种方式
- 提交表单的三种方式
- php Curl 里面模拟表单提交 文本+文件的写法
- 利用socket模拟http的混合表单上传(在一个请求中提交表单并上传多个文件)
- curl模拟post进行表单提交
- ExtJs中form表单提交的三种方式
- 防止表单重复提交的三种方式
- PHP的三种HTTP请求,php模拟post 提交
- 使用Curl、socket、file_get_contents三种方法POST提交数据
- 自定义Toast
- 视觉学习中典型的矩阵分解方式总结
- LazyMan深入解析和实现
- 2017-04-27 DBA日记,关于存储光纤交换机故障引发的数据库性能问题
- font-size,line-height,text-indent大小的设置方法(px,em,百分数)及其继承性
- socket,curl,file_get_content三种HTTP模拟表单提交的方式
- Linux系统网络配置
- Android Jenkins+gradle+git自动化构建并生成二维
- java工程师面试题
- 安卓scale动画pivotX详解
- 4、Volley解析(二),源码的深入分析一,缓存线程和网络请求线程
- 通用的业务编码规则设计实现
- window.location.href/replace/reload()--页面跳转+替换+刷新 区别
- Cognos原理