1、全局代码
Public Function CheckValidationResult(sender As Object, certificate As System.Security.Cryptography.X509Certificates.X509Certificate, chain As System.Security.Cryptography.X509Certificates.X509Chain, errors As System.Net.Security.SslPolicyErrors) As Boolean
' 总是接受
Return True
End Function
2、参考
dim bytes
dim requrl = "https://api.mch.weixin.qq.com/secapi/pay/refund"
Dim cert As String = "C:\cert\apiclient_cert.p12"
Dim password As String = "商户号"
System.Net.ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(addressof CheckValidationResult)
Dim cer As System.Security.Cryptography.X509Certificates.X509Certificate = New System.Security.Cryptography.X509Certificates.X509Certificate(cert, password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.MachineKeySet)
Dim webrequest As net.HttpWebRequest = net.HttpWebRequest.Create(reqUrl)
webrequest.ClientCertificates.Add(cer)
webrequest.Method = "post"
webrequest.ContentLength = bytes.Length
webrequest.GetRequestStream().Write(bytes, 0, bytes.Length)
Dim webreponse As Net.httpWebResponse = webrequest.GetResponse()
Dim stream As io.Stream = webreponse.GetResponseStream()
Dim resp As String = String.Empty
Using reader As io.StreamReader = New io.StreamReader(stream)
resp = reader.ReadToEnd()
End Using