PHP使用file_get_contents发送http请求功能简单示例
网络编程 2021-07-05 08:24www.168986.cn编程入门
这篇文章主要介绍了PHP使用file_get_contents发送http请求功能,结合实例形式分析了file_get_contents结合stream_context_create实现的发送post请求数据相关原理与操作技巧,需要的朋友可以参考下
本文实例讲述了PHP使用file_get_contents发送http请求功能。分享给大家供大家参考,具体如下:
服务器端模拟 POST/GET 等请求,使用 CURL 很容易办到(例如前面一篇《》),那么如果不使用 CURL 库,又该怎么办呢?
$data = array( 'test'=>'bar', 'baz'=>'boom', 'site'=>'.nimip.', 'name'=>'nimip.'); $data = http_build_query($data); //$postdata = http_build_query($data); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/x--form-urlencoded', 'content' => $data 'timeout' => 60 // 超时时间(单位:s) ) ); $url = "http://.testweb."; $context = stream_context_create($options); $result = file_get_contents($url, false, $context); echo $result;
其中http://.testweb.的代码为:
$data = $_POST; print_r( $data );
stream_context_create()
作用:创建并返回一个文本数据流并应用各种选项,可用于fopen()
,file_get_contents()
等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。
更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家PHP程序设计有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程