最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php stream_context_create函数
时间:2022-06-24 20:12:54 编辑:袖梨 来源:一聚教程网
函数原型:resource stream_context_create ([ array $options [, array $params ]] )
看个实例
//定义options数组
$opts=array
(
'http'=>array
(
'method'=>"get",
'header'=>"accept-language: enrn"."cookie: foo=barrn"
)
);
//创建数据流上下文
$context=stream_context_create($opts);
/*向指定地址发送http请求
请求中包含附加的头部信息*/
$fp=fopen('https://www.111cn.net','r',false,$context);
//输出文件指针处的所有数据
fpassthru($fp);
//关闭文件
fclose($fp);
/*
该代码的输出结果为:即请求的cookie值
array
(
[foo] => bar
)
*/
实例二
$default_opts=array
(
'http'=>array
(
'method'=>"get",
'header'=>"accept-language: enrn"."cookie: foo=bar",
'proxy'=>"tcp://10.54.1.39:8000"
)
);
$alternate_opts=array
(
'http'=>array
(
'method'=>"post",
'header'=>"content-type: application/x-www-form-urlencodedrn"."content-length: " . strlen("baz=bomb"),
'content'=>"baz=bomb"
)
);
$default=stream_context_get_default($default_opts);
$alternate=stream_context_create($alternate_opts);
/* sends a regular get request to proxy server at 10.54.1.39
* for using context options specified in $default_opts
*/
readfile('http://www.**ex*ample.com');
/* sends a post request directly to
* using context options specified in $alternate_opts
*/
readfile('http://www.exa*m*p*le.com', false, $alternate);
相关文章
- 无主之地4反向绑架成就怎么达成 反向绑架成就解锁攻略 09-19
- 无主之地4废弃强化人矿井开启方法 废弃强化人矿井怎么开启 09-19
- 泰坦之旅2调整游戏难度方法 怎么调整游戏难度 09-19
- 盛世天下第三集东宫迷情上全选项攻略 第三集东宫迷情上怎么过 09-19
- 盛世天下第二集夜宴惊魂全选项攻略 第二集夜宴惊魂怎么过 09-19
- 无主之地4e币使用方法 e币怎么用 09-19