类型为'System.UriFormatException'在System.dll中发生,但未在用户代码

本文关键字:System 代码 用户 dll UriFormatException 类型 | 更新日期: 2023-09-27 18:05:43

我每次运行应用程序时都得到这个错误,生成了uri,但是当我试图通过单击aspn网页上的按钮发送toast通知时,程序崩溃并显示该错误(类型为'System '的例外)。UriFormatException'发生在System.dll中,但没有在用户代码中处理)这是我的代码线程:[在HttpWebRequest请求上崩溃= (HttpWebRequest)WebRequest.Create(channelURI);line]

public string SendNotification(string message)
        {
            string channelURI = "PUT_YOUR_CHANNEL_URI_HERE";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(channelURI);
            request.Method = "POST";
            request.ContentType = "text/xml";
            request.Headers.Add("X-NotificationClass", "2");
            request.Headers.Add("X-WindowsPhone-Target", "toast");
            string notificationData = "<?xml version='"1.0'" encoding='"utf-8'"?>" +
        "<wp:Notification xmlns:wp='"WPNotification'">" +
           "<wp:Toast>" +
              "<wp:Text1>WP7 TOAST</wp:Text1>" +
              "<wp:Text2>" + message + "</wp:Text2>" +
           "</wp:Toast>" +
        "</wp:Notification>";
            byte[] contents = Encoding.Default.GetBytes(notificationData);
            request.ContentLength = contents.Length;
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(contents, 0, contents.Length);
            }
            string notificationStatus;
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                notificationStatus = response.Headers["X-NotificationStatus"];
            }
            return notificationStatus;
        }
    }

类型为'System.UriFormatException'在System.dll中发生,但未在用户代码

您原样复制了带有"PUT_YOUR_CHANNEL_URI_HERE"值的示例。您需要提供一个真正的通道URI,因为这个URI格式不正确,因此会抛出UriFormatException

相关文章: