当咱们有时用代码编写post请求url远程地址会报“基础链接已经关闭: 未能为 SSL/TLS 安全通道创建信任关系。 ---> System.Security.Authentication.AuthenticationException: 根据验证过程,远程证书无效。”这个异常,是由于远程url使用的域名 没有购买证书,因此用如下方式来解决:安全
ps:在create url以前 设定“获取或设置用于验证服务器证书的回调”永远为true 便可,具体以下服务器
post请求必定须要:System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);post
在这句代码前加上: ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;便可url
RemoteCertificateValidate事件代码以下:spa
private static bool RemoteCertificateValidate(object sender, X509Certificate cert,X509Chain chain, SslPolicyErrors error)
{
//为了经过证书验证,老是返回true
return true;
}事件
搞定域名