有人能寫再現這個Linux shell命令的功能的PHP腳本?PHP捲曲與 - 數據標誌?
curl -X POST -u "USERNAME:PASS" \
-H "Content-Type: application/json" \
--data '{"aps": {"alert": "this is a message"}}' \
https://mywebsite.com/push/service/
我覺得我幾乎得到了它在我的代碼,但我不知道如何處理--data
屬性。
這裏是我的代碼看起來像至今:
$headers = array();
$headers[] = "Content-Type: application/json";
$body = '{"aps":{"alert":"this is a message"}}';
$ch = curl_init();
// Set the cURL options
curl_setopt($ch, CURLOPT_URL, "https://mywebsite.com/push/service/");
curl_setopt($ch, CURLOPT_USERPWD, "USERNAME:PASSWORD");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
print_r($result);
你有代碼?好好把它放在我們身上! – dldnh 2012-03-18 22:28:20
剛剛添加了 – John 2012-03-18 22:33:03