Last active
September 17, 2021 10:30
-
-
Save slav123/4e3a6c2f671cf0c2960a to your computer and use it in GitHub Desktop.
PHP POST request 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 | |
$data = []; | |
// www-form-urlencoded | |
$opts = array('http' => array('method' => 'POST', | |
'header' => 'Content-Type: application/x-www-form-urlencoded', | |
'content' => http_build_query($data) | |
)); | |
// json | |
$opts = array('http' => array('method' => 'POST', | |
'header' => 'Content-Type: application/json\r\nAccept: application/json\r\n', | |
'content' => json_encode($data) | |
)); | |
$context = stream_context_create($opts); | |
$result_json = file_get_contents('http://...', FALSE, $context); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment