Last active
October 14, 2022 09:19
-
-
Save ytkhs/1000074 to your computer and use it in GitHub Desktop.
a sample POST method with file_get_contents()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('http_post_contents')) { | |
function http_post_contents($url, $params) { | |
$content = http_build_query($params, '', '&'); | |
$header = array( | |
"Content-Type: application/x-www-form-urlencoded", | |
"Content-Length: ".strlen($content) | |
); | |
$options = array( | |
'http' => array( | |
'method' => 'POST', | |
'content' => $content, | |
'header' => implode("\r\n", $header) | |
) | |
); | |
return file_get_contents($url, false, stream_context_create($options)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And years later, still useful! Thanks.