使用c#在Windows Phone 8.1中发送推送通知时出现404错误请求错误

时间:2016-09-18 14:38:13

标签: c# asp.net windows-phone-8 push-notification windows-phone-8.1

您好我正在使用Windows Phone 8.1 pushnotifications.but我收到了404 badrequest error.please帮帮我。下面是我的代码。

 string strChannelURI = https://hk2.notify.windows.com/?token=fgdggg/o0mhYNj9rWeJSQwvcBMGuVgDwAKXr/Q2N9C14HM7O+nVwJfZJdfG4fgvgfggfgg454545wTJg9LJ7euLWvxB0YXo7XQ4eWc=;


                //  string PushNotificationXML1 = "<toast launch=\"/text to receive\">" + "<visual>" + " <binding template=\"ToastImageAndText02\">" + " <text id=\"1\">" + Headertext + "</text>" + " <text id=\"2\">" + Message + "</text>" + "<image id=\"1\"  src=" + imageurl + "/>" + " </binding>" + " </visual>" + "</toast>";


                string PushNotificationXML1 = "<toast launch=\"/text to receive\">" + "<visual>" + " <binding template=\"ToastText02\">" + " <text id=\"1\">" + Headertext + "</text>" + " <text id=\"2\">" + Message + "</text>" + "</binding>" + " </visual>" + "</toast>";

                var accessToken1 = GetAccessToken("gdrr5tyrtr//xt4t5", "ms-app://s-1-15-2-dfd454454-45455-454566sdfdgxdf-1465454545444715-2331561566-544554-454e5454545445545fffdfffffd");

                string type = "wns/toast";
                HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(strChannelURI);
                sendNotificationRequest.Method = "POST";
                sendNotificationRequest.Headers.Add("X-WNS-Type", type);
                sendNotificationRequest.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken1.AccessToken));

                byte[] notificationMessage = Encoding.Default.GetBytes(PushNotificationXML1);
                // Set the web request content length.
                sendNotificationRequest.ContentLength = notificationMessage.Length;
                sendNotificationRequest.ContentType = "text/xml";
                sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
                sendNotificationRequest.Headers.Add("X-NotificationClass", "2");




                using (Stream requestStream = sendNotificationRequest.GetRequestStream())
                {
                    requestStream.Write(notificationMessage, 0, notificationMessage.Length);
                }
                // Send the notification and get the response.

                HttpWebResponse response;

                try
                {
                    response = (HttpWebResponse)sendNotificationRequest.GetResponse();
                    string notificationStatus = response.Headers["X-NotificationStatus"];
                    string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
                    string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
                }
                catch (WebException ex)
                {
                    response = ex.Response as HttpWebResponse;
                }

我从最近一周开始尝试这个,但是我得不到适当的回应。请帮助我。

0 个答案:

没有答案