HTTP POST in PHP5

<?php

$data = array('foo' => 'rhubarb');

// POST as form-encoded parameters
$context = stream_context_create(array('http' => array(
  'method' => 'POST',
  'content' => http_build_query($data),
)));

// POST as JSON
$context = stream_context_create(array('http' => array(
  'method' => 'POST',
  'content' => json_encode($data),
  'header' => 'Content-Type: application/json',
)));

$result = file_get_contents($url, null, $context);