Created
October 8, 2014 13:39
-
-
Save yuan3y/d3ea5ca6f65734f4ce6e to your computer and use it in GitHub Desktop.
Send parameters to url using POST or GET and show response HTML
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 | |
$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