Skip to content

Instantly share code, notes, and snippets.

@mohammadmursaleen
Created September 7, 2016 07:22
Show Gist options
  • Save mohammadmursaleen/3a486821ab612f158c6c5cf3d09dbbdd to your computer and use it in GitHub Desktop.
Save mohammadmursaleen/3a486821ab612f158c6c5cf3d09dbbdd to your computer and use it in GitHub Desktop.
Send Post Request to URL and get response using PHP
<?php
/**
* @author : Mohammad Mursaleen
* @usage : Send Post Request to URL and get response using PHP
*/
$url = 'URL';
$data = array('field1' => 'value', 'field2' => 'value');
$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