推送通知(使用android的GCM)在本地主机上工作良好,但在生产服务器上工作失败

本文关键字:工作 失败 服务器 主机 使用 通知 android GCM | 更新日期: 2023-09-27 18:12:09

我已经使用Push通知在我的web应用程序使用asp.net webformsPush通知在连接实时数据库的本地主机上工作正常,但在生产服务器上工作失败。

问题是什么?

我需要改变我的webConfig文件?????

请建议

    public static void CallPUshNotiFication(string Msg,string EmailId,string PageName)
        {
            try
            {
                DataSet dsregID = new DataSet();
                StringBuilder strBldId = new StringBuilder();
               
                var applicationID = Validate.ApplicationId;
                var SENDER_ID = Validate.SenderId;
                List<MobileRegistration11> PuschList = MobileRegistrationManager1.GetDataFromMobileRegistration1(EmailId);
                if (PuschList.Count > 0)
                {
                    foreach (var item in PuschList)
                    {
                       
                        string regId = Convert.ToString(item.RegistrationId);
                        
                        WebRequest tRequest;
                        tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
                        //
                        tRequest.UseDefaultCredentials = true;
                        tRequest.PreAuthenticate = true;
                        tRequest.Credentials = CredentialCache.DefaultCredentials;
                        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="
                            + Msg + "&registration_id=" + regId + "&data.id=" + PageName+ "&data.recordId="+147+"";
                        
                        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();
                        strBldId.Append(sResponseFromServer + "<br>"); //printing response from GCM server.
                        tReader.Close();
                        dataStream.Close();
                        tResponse.Close();
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }

推送通知(使用android的GCM)在本地主机上工作良好,但在生产服务器上工作失败

如果您可以访问您的机器,那么尝试在命令行上运行此命令。

替换主题和键。你可能需要安装curl

curl -X POST -H "Content-Type: application/json" -H "Authorization: key=<PUT your key>" -d '{
   "condition": "'"'"'<Put your topic>' in topics",
  "data": {
    "payload": ""
   }
}
' "https://fcm.googleapis.com/fcm/send"

如果这是正确的响应,那么我们可以确定您的机器能够访问GCM服务器。然后我们再谈别的。

谢谢