The easiest way to send basic HTTP POST or GET requests is using PHP’s built in file_get_contents() function in conjunction with HTTP context options:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$data = http_build_query( array( 'firstKey' => 'firstValue', 'secondKey' => 'secondValue', 'thirdKey' => 'thirdValue' ) ); $options = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $data ) ); $context = stream_context_create($options); $result = file_get_contents('https://httpbin.org/post', false, $context); |
Further reading: