Last active
August 28, 2015 17:50
-
-
Save jakebathman/8e5057ba33d5315950df to your computer and use it in GitHub Desktop.
GroupMe API post
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
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