Asp.net| Request
There was a debugging error in the HTTPS request for today's project, internal error: Failed to establish a trust relationship for the SSL/TLS secure channel. Error page: The remote certificate is not valid according to the authentication process. After analysis, open in the browser to make a security confirmation. This is the problem that this dialog box causes. Search the Internet for a general solution, but the content of the search is relatively small, now summed up 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 under 2.0 ServicePointManager.CertificatePolicy already obsolete
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;
}
}
}