PHP请求http(file_get_content)
2013-03-23 00:00
706 查看
PHP的http请求在很久之前就写过了,直接搬上来吧。
1.GET方式请求
[php]
view plain
copy
<?php
$data = array('sParam1'=>'test1','sParam2'=>101,'isAuto'=>1); //定义参数
$data = @http_build_query($data); //把参数转换成URL数据
$aContext = array('http' => array('method' => 'GET',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $data ));
$cxContext = stream_context_create($aContext);
$sUrl = 'http://www.mytest.com/test.php'; //此处必须为完整路径
$d = @file_get_contents($sUrl,false,$cxContext);
print_r($d);
?>
2.POST方式请求
[python]
view plain
copy
<?php
$data = array('sParam1'=>'test1','sParam2'=>101,'isAuto'=>1); //定义参数
$data = @http_build_query($data); //把参数转换成URL数据
$aContext = array('http' => array('method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $data ));
$cxContext = stream_context_create($aContext);
$sUrl = 'http://www.mytest.com/test.php'; //此处必须为完整路径
$d = @file_get_contents($sUrl,false,$cxContext);
print_r($d);
?>
1.GET方式请求
[php]
view plain
copy
<?php
$data = array('sParam1'=>'test1','sParam2'=>101,'isAuto'=>1); //定义参数
$data = @http_build_query($data); //把参数转换成URL数据
$aContext = array('http' => array('method' => 'GET',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $data ));
$cxContext = stream_context_create($aContext);
$sUrl = 'http://www.mytest.com/test.php'; //此处必须为完整路径
$d = @file_get_contents($sUrl,false,$cxContext);
print_r($d);
?>
2.POST方式请求
[python]
view plain
copy
<?php
$data = array('sParam1'=>'test1','sParam2'=>101,'isAuto'=>1); //定义参数
$data = @http_build_query($data); //把参数转换成URL数据
$aContext = array('http' => array('method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $data ));
$cxContext = stream_context_create($aContext);
$sUrl = 'http://www.mytest.com/test.php'; //此处必须为完整路径
$d = @file_get_contents($sUrl,false,$cxContext);
print_r($d);
?>
相关文章推荐
- PHP请求http(file_get_content)
- PHP http(file_get_content) GET与POST请求方式
- PHP http(file_get_content) GET与POST请求方式
- PHP http(file_get_content) GET与POST请求方式
- PHP为fopen,file_get_contents等函数请求web地址时增加Http头的方法
- PHP使用file_get_contents或curl请求https的域名内容为空或Http 505错误的问题排查方法
- php中curl、fsocket、file_get_content三个函数的使用比较
- php 采集类snoopy http://www.jb51.net/article/27568.htm | cURL、file_get_contents、snoopy.class.php 优缺点
- php中file_get_content 和curl以及fopen
- PHP使用http_build_query()构造URL字符串的方法(可将POST参数组转换拼接成GET请求链接)
- PHP之文件操作,http请求数据格式,模拟get和post,CURL模拟请求的使用
- php中file_get_content 和curl以及fopen 效率分析
- PHP使用file_get_content设置头信息的方法
- php中curl和file_get_content的区别
- php中curl和file_get_content的区别
- php中curl和file_get_content的区别
- 关于PHP程序使用file_get_content()函数进行抓取PHP程序与smarty结合编译过程中产生的静态文件,抓取不了?连接超时?(地址映射)
- PHP解决[function.file-get-contents]: failed to open stream: HTTP request failed!
- 关于原生JavaScript的http全部请求 post get json xml file 全了 拿去救急
- PHP使用file_get_content设置头信息的方法