Skip to content

Instantly share code, notes, and snippets.

@yuan3y
Created October 8, 2014 13:39
Show Gist options
  • Save yuan3y/d3ea5ca6f65734f4ce6e to your computer and use it in GitHub Desktop.
Save yuan3y/d3ea5ca6f65734f4ce6e to your computer and use it in GitHub Desktop.
Send parameters to url using POST or GET and show response HTML
<?php
$method = 'GET'; //change to 'POST' for post method
$url = 'http://localhost/browse/';
$data = array(
'manufacturer' => 'kraft',
'packaging_type' => 'bag'
);
if ($method == 'POST'){
//Make POST request
$data = http_build_query($data);
$context = stream_context_create(array(
'http' => array(
'method' => "$method",
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $data)
)
);
$response = file_get_contents($url, false, $context);
}
else {
// Make GET request
$data = http_build_query($data, '', '&');
$response = file_get_contents($url."?".$data, false);
}
echo $response;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment