Skip to content

Instantly share code, notes, and snippets.

@dengsauve
Created January 28, 2019 20:51
Show Gist options
  • Save dengsauve/5a8632e76af0d04b6f1dca5717ae9963 to your computer and use it in GitHub Desktop.
Save dengsauve/5a8632e76af0d04b6f1dca5717ae9963 to your computer and use it in GitHub Desktop.
PHP Curl-less POST request
$url = 'http://server.com/path';
$data = array('key1' => 'value1', 'key2' => 'value2');
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment