$cURL = curl_init();
// set url
curl_setopt($cURL, CURLOPT_URL, $url);
// set method default is GET
// curl_setopt($cURL, CURLOPT_CUSTOMREQUEST, "POST");
// set header
$deviceId = '1234567890'; // custom header field
$appVersion = '1.0.0'; // custom header field
$header = array(
'Content-Type: application/json',
// 'Content-Length: ' . strlen($data_string) // optional
'Accept: application/json',
'version: '.$appVersion,
'deviceId: '.$deviceId
)
curl_setopt($cURL, CURLOPT_HTTPHEADER, $header);
// set json post data
$data = array("email" => "user@acc.com", "password" => "123456");
$data_string = json_encode($data);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $data_string);
$result = curl_exec($$cURL);
// curl result:
{
"status": 200,
"message": "success",
"result": [
{
"id": "5a6032ae755b9e0585dc8f21",
"name": "Zone A",
"address": "Lake Side"
},
{
"id": "5a6032e0755b9e0585dc8f22",
"name": "Zone B",
"address": "Forest Side"
},
{
"id": "5a6067db755b9e547bfa52c4",
"name": "Zone C",
"address": "Forest Side"
}
]
}
// parse json result
$json = json_decode($result, true);
// '{"Cancelled":false,"MessageID":"402f481b-c420-481f-b129-7b2d8ce7cf0a","Queued":false,"SMSError":2,"SMSIncomingMessages":null,"Sent":false,"SentDateTime":"\/Date(-62135578800000-0500)\/"}'
// Array
// (
// [Cancelled] =>
// [MessageID] => 402f481b-c420-481f-b129-7b2d8ce7cf0a
// [Queued] =>
// [SMSError] => 2
// [SMSIncomingMessages] =>
// [Sent] =>
// [SentDateTime] => /Date(-62135578800000-0500)/
// )