我已经设置了该功能在我的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
上一篇:与蓝牙在Android的内核开发的Linux工作蓝牙、内核、工作、Android
下一篇:GoogleApiClient onConnected从来没有所谓的可穿戴设备从来没有、穿戴、设备、GoogleApiClient