none
Push Notification问题:向Uri发送消息时,远程服务器返回错误: (400) 错误的请求 RRS feed

  • 问题

  • 如题,之前服务器还可以正常返回信息,也没改代码

    Uri:http://hk1.notify.live.net/throttledthirdparty/01.00/AQGGyU7SwMLcS4l6vtZfTNAgAAAAADAQAAAAUZm52OkJCMjg1QTg1QkZDMkUxREQFBkFTRUEwMQ

    Uri可以直接访问,但就是不能向它发数据,难道toast格式变了?还是服务器的什么原因?求解答

     try
                {
                    string subscriptionUri = url.Text.ToString();

                    HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);

                    sendNotificationRequest.Method = "POST";

                    string toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                    "<wp:Notification xmlns:wp=\"WPNotification\">" +
                       "<wp:Toast>" +
                            "<wp:Text1>" + "Woqu" + "</wp:Text1>" +
                            "<wp:Text2>" + msg.Text.ToString() + "</wp:Text2>" +
                            "<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>" +
                       "</wp:Toast> " +
                    "</wp:Notification>";

                    byte[] notificationMessage = Encoding.Default.GetBytes(toastMessage);

                    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);
                    }

                    HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
                    string notificationStatus = response.Headers["X-NotificationStatus"];
                    string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
                    string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];

                    state.Text = notificationStatus + " | " + deviceConnectionStatus + " | " + notificationChannelStatus;
                }
                catch (Exception ex)
                {
                    state.Text = "Exception caught sending update: " + ex.ToString();
                }

    2013年11月14日 3:35