CURL-less method:
$url = 'http://server.com/path';
$data = ['key1' => 'value1', 'key2' => 'value2'];
// use key 'http' even if you send the request to https://...
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
],
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === false) {
/* Handle error */
}
var_dump($result);
See the PHP manual for more information on the method and how to add headers, for example:
- stream_context_create: https://www.php.net/manual/en/function.stream-context-create.php