0
我試圖發送推送通知到多個android設備。發送推送通知到多個Android設備使用asp .net
對於一個設備它的工作,但是當我試圖添加多個設備 registrationIDs那麼它不; GCM返回錯誤= InvalidRegistration
var Message = tMessage.Text; //message text box
var Title = tTitle.Text;
string stringregIds = null;
List<string> regIDs = new List<string>();
regIDs.Add(redIdEmulNew);
regIDs.Add(regIdMobileNew);
stringregIds = string.Join("\",\"", regIDs);
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}", applicationID));
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="
+ Message + "&data.title=" + Title + "®istration_id=" +
stringregIds + "";
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(); //Get response from GCM server.
lbResponse.Text = sResponseFromServer; //Assigning GCM response to Label text
tReader.Close();
dataStream.Close();
tResponse.Close();
我懷疑下面的代碼有問題:
string stringregIds = null;
List<string> regIDs = new List<string>();
regIDs.Add(redIdEmulNew);
regIDs.Add(regIdMobileNew);
stringregIds = string.Join("\",\"", regIDs);
兩個設備註冊ID是有效的,我已經分別檢查推送通知。
由於
tRequest.ContentType =「應用/ JSON「; - 設置正確的格式以符合Ashok建議的更改。 –