我正在嘗試使用C#推送GCM。我成功地將消息發送到手機。但只是整個字符串與參數一起出現在手機上,而不是單獨的「消息」參數。
即:爲我的消息字符串:「gcmAction = gcmActionFeedback,標題=請提供反饋,消息=您的反饋意見,請」
在電話中通知我能看到「gcmAction = gcmActionFeedback,標題=請提供反饋,消息=您的反饋請「在我應該看到的地方」只有您的反饋「。
標題也未顯示。而當我通過http://gcm-alert.appspot.com/發送相同的GCM消息時,一切看起來都很完美。GCM參數與消息一起顯示
Plz plz help。這是代碼
public string SendNotification2(string deviceId, string message)
{
string GoogleAppID = "AIza.......xkQk";
var SENDER_ID = "6666666666";
var value = message;
WebRequest tRequest;
tRequest = WebRequest.Create(" https://android.googleapis.com/gcm/send ");
tRequest.Method = "post";
tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", GoogleAppID));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" +
System.DateTime.Now.ToString() + "®istration_id=" + deviceId + "";
Console.WriteLine(postData);
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
return sResponseFromServer;
}
工作完美髮送此playload在體內。非常感謝! –