Skip to content

Instantly share code, notes, and snippets.

@jakebathman
Last active August 28, 2015 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakebathman/8e5057ba33d5315950df to your computer and use it in GitHub Desktop.
Save jakebathman/8e5057ba33d5315950df to your computer and use it in GitHub Desktop.
GroupMe API post
public function apiPost($url, $data = array() , $boolHeaders = false)
{
$ch = curl_init($url);
if (empty($data['file']))
{
$data = json_encode($data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
));
}
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($boolHeaders !== false)
{
curl_setopt($ch, CURLOPT_HEADER, 1);
$c = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = $this->get_headers_from_curl_response(substr($c, 0, $header_size));
$body = json_decode(substr($c, $header_size) , true);
return array(
"response" => $body,
"headers" => $header[0]
);
}
else
{
$c = curl_exec($ch);
return $c;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment