内容简介:Daniel – Dude GCM文档存在问题!使用Browser密钥作为Server API密钥位置的授权密钥.它会工作.翻译自:https://stackoverflow.com/questions/11431261/unauthorized-when-calling-google-gcm
我尝试使用Google GCM发送推送通知.但得到一个WebException,说远程服务器返回401 unautorized.我无法理解为什么它不起作用.
有谁知道它为什么不起作用?
这是我的代码:
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateServerCertificate); HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send"); Request.Method = "POST"; Request.KeepAlive = false; string postData = "{ 'registration_ids': [ '"+registrationId+"' ], 'data': {'message': '"+message+"'}}"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); Request.ContentType = "application/json"; //Request.ContentLength = byteArray.Length; //Request.Headers.Add(HttpRequestHeader.Authorization, "GoogleLogin auth=" + AuthString); Request.Headers.Add(HttpRequestHeader.Authorization, "Authorization: key=AIzaSyCEygavdzrNM3pWNPtvaJXpvW66CKnjH_Y"); //-- Delegate Modeling to Validate Server Certificate --// //-- Create Stream to Write Byte Array --// Stream dataStream = Request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); //-- Post a Message --// WebResponse Response = Request.GetResponse(); HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode; if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden)) { var text = "Unauthorized - need new token"; } else if (!ResponseCode.Equals(HttpStatusCode.OK)) { var text = "Response from web service isn't OK"; } StreamReader Reader = new StreamReader(Response.GetResponseStream()); string responseLine = Reader.ReadLine(); Reader.Close();
Daniel – Dude GCM文档存在问题!使用Browser密钥作为Server API密钥位置的授权密钥.它会工作.
翻译自:https://stackoverflow.com/questions/11431261/unauthorized-when-calling-google-gcm
以上所述就是小编给大家介绍的《c# – 在致电Google GCM时未经授权》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- Android安全审核(调查未经授权的屏幕截图)
- Facebook 未经允许“无意中上传”了 150 万用户的电子邮件联系人
- MikroTik RouterOS未经认证可绕过防火墙访问NAT内部网络(CVE-2019-3924)
- 安天针对Cisco RV320、RV325未经授权的远程代码执行漏洞的分析及建议
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Web Security, Privacy and Commerce, 2nd Edition
Simson Garfinkel / O'Reilly Media / 2002-01-15 / USD 44.95
Since the first edition of this classic reference was published, World Wide Web use has exploded and e-commerce has become a daily part of business and personal life. As Web use has grown, so have ......一起来看看 《Web Security, Privacy and Commerce, 2nd Edition》 这本书的介绍吧!