ちょっと特殊な使い方だけどすごく便利。
function postExecute($target, $data)
{
$query = http_build_query($data, '', '&');
$header = [
'Content-Type: application/x-www-form-urlencoded',
'Content-Length: '.strlen($query)
];
$context = [
'http' => [
'method' => 'POST',
'header' => implode("\r\n", $header),
'content' => $query
]
];
return file_get_contents($target, false, stream_context_create($context));
}
$targetにはポスト先URLを指定、$dataにはポストしたいデータを配列で渡せばOK。