1
我想從WCF休息服務向Kindle Fire發送推送通知。如何通過WCF休息服務向Kindle Fire發送推送通知
我使用PushSharp庫,但它不能正常工作。你能不能使用PushSharp庫建議任何其他方式?
我使用下面的代碼到Kindle上發送通知是給錯誤400,
private void sendNotification(String registrationID)
{
String message = "{data\": {\"NTY\":\"-1\",\"NOTY\": \"2\"}}";
String title="title";
String accessToken = "";
accessToken = UpdateAccessToken();
HttpWebRequest httpWReq =
(HttpWebRequest)WebRequest.Create("https://api.amazon.com/messaging/registrations/" + registrationID + "/messages");
Encoding encoding = new UTF8Encoding();
string postData = "{\"data\":{\"message\":\"" + message + "\",\"title\":\"" + title + "\"},\"consolidationKey\":\"Some Key\",\"expiresAfter\":86400}";
byte[] data = encoding.GetBytes(postData);
httpWReq.ProtocolVersion = HttpVersion.Version11;
httpWReq.Method = "POST";
httpWReq.ContentType = "application/json";//charset=UTF-8";
httpWReq.Headers.Add("X-Amzn-Type-Version",
"[email protected]");
httpWReq.Headers.Add("X-Amzn-Accept-Type",
"[email protected]");
httpWReq.Headers.Add(HttpRequestHeader.Authorization,
"Bearer " + accessToken);
httpWReq.ContentLength = data.Length;
Stream stream = httpWReq.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
string s = response.ToString();
StreamReader reader = new StreamReader(response.GetResponseStream());
String jsonresponse = "";
String temp = null;
while ((temp = reader.ReadLine()) != null)
{
jsonresponse += temp;
}
}
謝謝,它的使用完全可以你給我它實現的代碼示例? – aemie
亞馬遜網站有一個很好的演練來實現這 – Offbeatmammal
我讀過它,但我不明白我如何使用它,我嘗試了一些東西,但它不工作。我也發郵件給亞馬遜支持團隊,但他們沒有回覆。我可以給我代碼示例。 – aemie