WebException被抓住了。远程服务器返回错误:(403)禁止

时间:2016-08-31 07:35:19

标签: c# ios apple-push-notifications everlive

我正在尝试从后端向iOS设备发送推送通知。当我运行我的服务时,抛出此异常。 "远程服务器返回错误:(403)禁止。"这是我在c#中的代码:

string appid = "my_app_id";
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://api.everlive.com/v1/"+appid+"/Push/Notifications");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
IWebProxy myProxy = httpWebRequest.Proxy;
myProxy.Credentials = new NetworkCredential("", "", "IFMUK");
if (myProxy != null)
{
    // Use the default credentials of the logged on user.
    myProxy.Credentials = CredentialCache.DefaultCredentials;
}
httpWebRequest.Proxy = myProxy;
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
    string notificationMessage = "These are not the droids you are looking for";
    string json = "{\"Filter\":\"{\\\"$and\\\":[{\\\"Parameters.User\\\":\\\"" + "Luke".ToLower() + "\\\"}]}\",\"NotificationDate\":null,\"ExpirationDate\":null,\"IOS\":null,\"Android\":null,\"WindowsPhone\":null,\"Windows\":null,\"Message\":\"" + notificationMessage + "\",\"UseLocalTime\":false}";
    streamWriter.Write(json);
    streamWriter.Flush();
    streamWriter.Close();
} 
HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
WebHeaderCollection header = httpResponse.Headers;
var encoding = ASCIIEncoding.ASCII;
using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), encoding))
{
    var res = streamReader.ReadToEnd();
}

如果有人能帮助我解决问题,我将不胜感激。 提前致谢!

0 个答案:

没有答案