我在使用c#发送推送通知时收到错误(远程服务器返回了error: (422) Unprocessable Entity.)
。我正在向所有可能的设备发送notification
。
然后我在这一行收到错误
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
以下是代码:
try
{
String token = GetToken();
HttpWebRequest httpWReq;
httpWReq = (HttpWebRequest)WebRequest.Create(System.Configuration.ConfigurationManager.AppSettings["QuickUrl"].ToString().Trim() + "events.xml");
byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes("Pending Request Notification");
string base64Msg = System.Convert.ToBase64String(plainTextBytes);
String postData = "event[notification_type]=push";
postData += "&event[environment]=development";
postData += "&event[message]=" + base64Msg;
postData += "&event[ios_badge]=" + userPendingFriendRequestCount;
postData += "&event[ios_sound]=default";
postData += "&event[user][ids]={" + QuickBloxID + "}";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
httpWReq.UserAgent = ".NET Framework Test Client";
httpWReq.Method = "POST";
httpWReq.ContentLength = data.Length;
httpWReq.Headers["QuickBlox-REST-API-Version"] = "0.1.0";
httpWReq.Headers["QB-Token"] = token;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();//The remote server returned an error: (422) Unprocessable Entity.
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
XDocument xmlDoc = XDocument.Parse(responseString);
IsNotificationSent = true;
}
catch (Exception ex)
{
// new ErrorLogger().LogException(ex, "QBBAL-->addupdateDriverUserInQuickBlox");
}