Last active
December 13, 2015 17:49
-
-
Save stephenreid/4951024 to your computer and use it in GitHub Desktop.
Takes GET url w/ Post Parameters and sends the request on to a very basic rest server.
This file contains 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 | |
class apiProcessor{ | |
private $gets; | |
private $posts; | |
public function __construct($gets,$posts){ | |
$this->gets = $gets; | |
$this->posts = $posts; | |
} | |
public function process(){ | |
$url = $this->gets['url']; | |
$context = stream_context_create(array( | |
'http' => array( | |
'method' => 'POST',//never want to send credentials over GET | |
'header' => 'Content-type: application/x-www-form-urlencoded', | |
'content' => http_build_query($this->posts), | |
'timeout' => 30.0, //in seconds | |
'user_agent'=> 'XMLToJsonAPIClient', | |
) | |
)); | |
$res = file_get_contents($url,false,$context); | |
$xmlObject = simplexml_load_string($res); | |
$json = json_encode($xmlObject); | |
return $json; | |
} | |
} | |
$processor = new apiProcessor($_GET,$_POST); | |
echo $processor->process(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment