Skip to content

Instantly share code, notes, and snippets.

@AngeloR
Created February 10, 2014 16:17
Show Gist options
  • Save AngeloR/8918794 to your computer and use it in GitHub Desktop.
Save AngeloR/8918794 to your computer and use it in GitHub Desktop.
class Rest_Client {
/**
*
* Perform any get type operation on a url
* @param string $url
* @return string The resulting data from the get operation
*/
public static function get($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
/**
*
* Perform any post type operation on a url
* @param string $url
* @param array $params A list of post-based params to pass
*/
public static function post($url,array $params = array()) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment