您的位置:首页 > 理论基础 > 计算机网络

PHP http(file_get_content) GET与POST请求方式

2016-04-22 15:01 423 查看
转自:http://blog.csdn.net/chaoping315/article/details/19013237

1.GET方式请求

[php] view
plaincopy

<?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
plaincopy

<?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);

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: