使用.NET的Android C2DM沟通 [英] Communicating with Android C2DM using .NET
本文介绍了使用.NET的Android C2DM沟通的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经设置了该功能在我的web应用发送推送通知到Android设备:
I've set up this function in my web app to send push notifications to Android devices:
Private Function SendNotification(ByVal authstring As String) As String
Dim request As WebRequest = WebRequest.Create("https://android.apis.google.com/c2dm/send")
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
request.Headers.Add(String.Format("Authorization: GoogleLogin auth={0}", authstring))
Dim postData As String = String.Format("registration_id={0}&data.payload={1}&collapse_key=0", deviceList.SelectedValue, txtPayload.Text)
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
reader.Close()
dataStream.Close()
response.Close()
Return responseFromServer
End Function
不过,每当我调用这个函数,我得到以下错误信息:根据验证过程的远程证书无效
However, whenever I call this function, I get the following error message: The remote certificate is invalid according to the validation procedure."
这是什么,我可能是错在这里做有什么想法?我也试过在IIS上运行这一点,但没有帮助。
Any thoughts on what I might be doing wrong here? I also tried running this on IIS but that didn't help.
推荐答案
好吧,我想通了这一点,很多浏览各地后。我错过了这条线在我的code(应该是在函数的第一行):
Ok, I figured this out after a lot of browsing around. I was missing this line in my code (should be at the first line of the function):
ServicePointManager.ServerCertificateValidationCallback = Function(sender As _
Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As _
SslPolicyErrors) True
这篇关于使用.NET的Android C2DM沟通的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文