Skip to content

Instantly share code, notes, and snippets.

@tebajanga
Forked from iNaD/request_no_curl.php
Created August 27, 2018 12:53
Show Gist options
  • Save tebajanga/1e8b84114c9867ef9a2ccc5c14bb0e8a to your computer and use it in GitHub Desktop.
Save tebajanga/1e8b84114c9867ef9a2ccc5c14bb0e8a to your computer and use it in GitHub Desktop.
Sending a GET/POST Request via PHP without CURL (fopen needs to be enabled)
<?php
$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);
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment