LVPHP

php file_get_contents

使用file_get_contents发送post请求

1
2
3
4
5
6
7
8
9
10
11
$data = ['eat'=>'2kg','run'=>'10km'];
$url = 'http://localhost';
$context = stream_context_create(array(
'http' => array(   
'method' => 'POST',   
'header' => 'Content-type:application/x-www-form-urlencoded',   
'content' => html_build_query($info),   
'timeout' => 3
)
));
$result = file_get_contents($url, false, $context);