file_get_contents 模拟POST数据发送
2017-09-20 15:41
597 查看
<?php
$postDate = array(
'title' => '天气好',
'content' => '今天是星期三',
); // 要发送的数据
$postDate = http_build_query($postDate); //
使用给出的关联(或下标)数组生成一个 url-encoded 请求字符串。
$opts = array(
'http'=>array(
'method'=>"POST",// post请求
'header'=>"Host:localhost\r\n" .
"Content-type:application/x-www-form-urlencoded\r\n" .
"Content-length:".strlen($postDate)."\r\n", //
首部 \r\n 回车换行
'content' => $postDate,// 内容
)
);
$context = stream_context_create($opts);//创建并返回一个资源流上下文,该资源流中包含了提前设定的所有参数的值。
file_get_contents("http://localhost/index2.php",false,$context);//
发送(关键是第三个参数)
?>
$postDate = array(
'title' => '天气好',
'content' => '今天是星期三',
); // 要发送的数据
$postDate = http_build_query($postDate); //
使用给出的关联(或下标)数组生成一个 url-encoded 请求字符串。
$opts = array(
'http'=>array(
'method'=>"POST",// post请求
'header'=>"Host:localhost\r\n" .
"Content-type:application/x-www-form-urlencoded\r\n" .
"Content-length:".strlen($postDate)."\r\n", //
首部 \r\n 回车换行
'content' => $postDate,// 内容
)
);
$context = stream_context_create($opts);//创建并返回一个资源流上下文,该资源流中包含了提前设定的所有参数的值。
file_get_contents("http://localhost/index2.php",false,$context);//
发送(关键是第三个参数)
?>
相关文章推荐
- PHP模拟发送POST请求之四、加强file_get_contents()发送POST请求
- php 模拟浏览器 发送 post 和 get 请求(兼容curl + file_get_contents)
- PHP模拟发送POST请求之四、加强file_get_contents()发送POST请求
- php 模拟 post curl sock file_get_contents
- 【转】通过file_get_contents来Post数据的实例 BY 膘叔
- file_get_content 模拟POST数据
- C#模拟Post和Get方式发送数据 保持COOKIE
- C#模拟Post和Get方式发送数据
- PHP利用Curl、socket、file_get_contents POST数据
- asp.net mvc5取得post和get的数据和模拟发送
- file_get_contents post数据获取
- 使用Curl、socket、file_get_contents三种方法POST提交数据
- 利用Curl、socket、file_get_contents POST数据
- 调试json提交数据,模拟json发送数据POST或GET
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
- C#模拟Post和Get方式发送数据的技巧
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
- PHP中使用file_get_contents post数据代码例子
- 使用Curl、socket、file_get_contents三种方法POST提交数据
- C#模拟Post和Get方式发送数据