I came up with the following using cURL:
$ch = curl_init();
$arr = array();
array_push($arr, "X-Parse-Application-Id: YOUR_APPLICATION_ID");
array_push($arr, "X-Parse-REST-API-Key: YOUR_REST_API_KEY");
array_push($arr, "Content-Type: application/json");
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr);
curl_setopt($ch, CURLOPT_URL, 'https://api.parse.com/1/push');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "channel": "","data": { "alert": "Red Sox win 7-0!" } }');
curl_exec($ch);
curl_close($ch);
And if for some reason you don't want to use cURL, here is the code using the default stream_context_create and file_get_contents methods:
$url = 'https://api.parse.com/1/push';
$data = '{"channel":"","data":{ "alert":"Red Sox win 7-0!"}}';
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "X-Parse-Application-Id: YOUR_APPLICATION_ID\r\n
X-Parse-REST-API-Key: YOUR_REST_API_KEY\r\n
Content-Type: application/json\r\n
Content-Length: " . strlen($data) . "\r\n",
'content' => $data
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
echo $result;
none of the above methods are working
ReplyDeleteworking, to prevent result from sending header add the following line after curl_init(); this prevents header already sent error
ReplyDeletecurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);