Imports System.Net
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Public Class CertificateOverride Public Function RemoteCertificateValidationCallback( _
ByVal sender As Object, _
ByVal certificate As X509Certificate, _
ByVal chain As X509Chain, _
ByVal sslPolicyErrors As SslPolicyErrors _
) As Boolean
Return True End Function
End Class
Dim oCertOverride As New CertificateOverride'-- over ride the bad certificate error
ServicePointManager.ServerCertificateValidationCallback = _ AddressOf oCertOverride.RemoteCertificateValidationCallback'-- open the channel to web site
Dim oReq As WebRequest = _
System.Net.HttpWebRequest.Create("http://www.dashpoint.com")'-- set the credentials for HTTPS
Dim oCred As New System.Net.NetworkCredential("", "") oReq.Credentials = oCred'-- get a response from the site
Dim oResp As WebResponse = oReq.GetResponse()'-- attach the stream to a reader
Dim oSRead As New StreamReader(oResp.GetResponseStream)'-- get the content
Dim cContent As String = oSRead.ReadToEndMessageBox.Show(cContent)
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Public Class CertificateOverride Public Function RemoteCertificateValidationCallback( _
ByVal sender As Object, _
ByVal certificate As X509Certificate, _
ByVal chain As X509Chain, _
ByVal sslPolicyErrors As SslPolicyErrors _
) As Boolean
Return True End Function
End Class
Dim oCertOverride As New CertificateOverride'-- over ride the bad certificate error
ServicePointManager.ServerCertificateValidationCallback = _ AddressOf oCertOverride.RemoteCertificateValidationCallback'-- open the channel to web site
Dim oReq As WebRequest = _
System.Net.HttpWebRequest.Create("http://www.dashpoint.com")'-- set the credentials for HTTPS
Dim oCred As New System.Net.NetworkCredential("", "") oReq.Credentials = oCred'-- get a response from the site
Dim oResp As WebResponse = oReq.GetResponse()'-- attach the stream to a reader
Dim oSRead As New StreamReader(oResp.GetResponseStream)'-- get the content
Dim cContent As String = oSRead.ReadToEndMessageBox.Show(cContent)
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class CertificateOverride
{ public bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
}
CertificateOverride oCertOverride = new CertificateOverride();
ServicePointManager.ServerCertificateValidationCallback = /* might be wrong, please check */ new EventHandler(oCertOverride.RemoteCertificateValidationCallback);
WebRequest oReq = System.Net.HttpWebRequest.Create("http://www.dashpoint.com");
System.Net.NetworkCredential oCred = new System.Net.NetworkCredential("", "");
oReq.Credentials = oCred;
WebResponse oResp = oReq.GetResponse();
StreamReader oSRead = new StreamReader(oResp.GetResponseStream);
string cContent = oSRead.ReadToEnd;
MessageBox.Show(cContent);
这样?
应该这样,谢谢