Post请求
(1) 发送POST请求
<?php
function send_post($url,$post_data=''){
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($post_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
print_r($result);
}
$url='http://127.0.0.1/xx_platform/sync_client/sync.php';
send_post($url,$post_data=array('op'=>'rose99','action'=>'13'));
接受Post请求
<?php
// 定义主方法
// function mainLogic(){
// print_r("fsdaf");
// }
// 接收post过来的请求
$data = $_POST['op'];
$data1 = $_POST['action'];
$ret_array = ['ret' => 0, 'msg' => $data,'actn'=>$data1];
print_r($ret_array);
// echo file_get_contents("php://input") //获取所有传过来的值
// print_r($_POST); // 获取所有post传过来的值
Get请求
(2) 发送Get请求
<?php
$url='http://www.baidu.com/';
$html = file_get_contents($url);
echo $html;