【发布时间】:2015-07-30 21:15:26
【问题描述】:
我每次运行应用程序时都会收到此错误,生成 uri 但是当我尝试通过单击 aspn 网页上的按钮发送 toast 通知时,程序崩溃并显示该错误(“系统”类型的异常.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;
}
}
【问题讨论】:
标签: c# httpwebrequest uri