<?php
$data = [
'author' => 'jack',
'email' => '110@qq.com',
'text' => '给力给力',
];
$data = http_build_query($data);
$opts = [
'http' => [
'method' => 'POST',
'header' => "Content-type:application/x-www-form-urlencoded\r\n" . "Content-Length:" . strlen($data) . "\r\n",
'content' => $data,
]
];
$context = stream_context_create($opts);
$url = 'http://localhost/test/response.php';
$html = file_get_contents($url, false, $context);
echo $html;
http://localhost/test/response.php 此URL中包含的代码
····
<?php
$data = json_encode($_POST);
file_put_contents('./a.txt', $data, FILE_APPEND);
····