Skip to content

Instantly share code, notes, and snippets.

@jakebathman

jakebathman/groupMeApi.php

Last active Aug 28, 2015
Embed
What would you like to do?
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