我已在我的网络应用中设置此功能,以向Android设备发送推送通知:
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
但是,每当我调用此函数时,都会收到以下错误消息:根据验证过程,远程证书无效。“
对我在这里做错了什么的想法?我也尝试在IIS上运行它,但这没有帮助。
答案 0 :(得分:2)
好的,经过大量的浏览,我想到了这一点。我的代码中缺少这一行(应该在函数的第一行):
ServicePointManager.ServerCertificateValidationCallback = Function(sender As _
Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As _
SslPolicyErrors) True