I encountered this debugging error when making https requests in my project today. Internal error: Failed to establish trust relationship for SSL/TLS secure channel. Error page: The remote certificate is invalid according to the verification process. After analysis, a security confirmation is required when opening in a browser. This is the problem caused by this dialog box. I searched for general solutions on the Internet, but the search content was relatively small. Now I will summarize it here.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//for 1.1 ServicePointManager.CertificatePolicy is obsolete under 2.0
//ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
//for 2.0
//ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(" https://someurl ");
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
Page.Response.Write(readStream.ReadToEnd());
response.Close();
readStream.Close();
}
//for 2.0
public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ // Always accept
return true;
}
//for 1.1
internal class AcceptAllCertificatePolicy : ICertificatePolicy
{
public AcceptAllCertificatePolicy()
{
}
public bool CheckValidationResult(ServicePoint sPoint, System.Security.Cryptography.X509Certificates.X509Certificate cert, WebRequest wRequest, int certProb)
{
//Always accept
return true;
}
}
}
http://www.cnblogs.com/david8k/archive/2006/11/06/551911.html