在用HttpClient发起https请求时,遭遇了“The remote certificate is invalid according to the validation procedure”异常,异常信息如下:

Exception Details: System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

[AuthenticationException: The remote certificate is invalid according to the validation procedure.]
System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) +8622023
System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) +225 [WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.]
System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) +3564749
System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) +155

HttpClient调用代码如下:

var httpClient = new HttpClient();
var httpContent = new FormUrlEncodedContent(new
Dictionary<string, string>
{
{"grant_type", "client_credentials"}
});
var response = await httpClient.PostAsync("https://...", httpContent);

解决方法:

在web.config中添加如下的配置:

<system.net>
<settings>
<servicePointManager checkCertificateName="false" checkCertificateRevocationList="false" />
</settings>
</system.net>

解决“The remote certificate is invalid according to the validation procedure”问题的更多相关文章

  1. The remote certificate is invalid according to the validation procedure 远程证书验证无效

    The remote certificate is invalid according to the validation procedure   根据验证过程中远程证书无效 I'm calling ...

  2. (转)The remote certificate is invalid according to the validation procedure

    If you get “The remote certificate is invalid according to the validation procedure” exception while ...

  3. .net core中Grpc使用报错:The remote certificate is invalid according to the validation procedure.

    因为Grpc采用HTTP/2作为通信协议,默认采用LTS/SSL加密方式传输,比如使用.net core启动一个服务端(被调用方)时: public static IHostBuilder Creat ...

  4. 异常处理之“The remote certificate is invalid according to the validation praocedure.”

    参考文章:http://brainof-dave.blogspot.com.au/2008/08/remote-certificate-is-invalid-according.html 参考文章:h ...

  5. use AP_VENDOR_PUB_PKG.Update_Vendor_Site_Public to u ORA-01722: invalid number in Package AP_VENDOR_PUB_PKG Procedure Update_Vendor_Site_Public

    ORA-01722: invalid number in Package AP_VENDOR_PUB_PKG Procedure Update_Vendor_Site_Public 发现此问题的经过: ...

  6. 解决MAC下xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)的问题

    将系统升级到了最新10.13.3 macOS High Sierra后,在使用ctags命令时会出现如下问题: xcrun: error: invalid active developer path ...

  7. 解决WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

    问题: 当我想要利用win10本地的cmd进行: ssh root@192.168.1.230 时,出现了如下错误: C:\Users\Raodi>ssh root@192.168.1.230 ...

  8. 解决cvc-complex-type.2.4.a: Invalid content was found starting with element

    今天用myeclipse导入 一个项目出现后出现cvc-complex-type.2.4.a: Invalid content was found starting with element 'inf ...

  9. 解决"The remote SSH server rejected X11 forwarding request"问题

    今天突然想起来好久没有登录我的vps了,于是下载了xshell,填入地址登录后,看到提示"WARNING! The remote SSH server rejected X11 forwar ...

随机推荐

  1. js学习之--Bootstrap Modals(模态框)

    http://www.runoob.com/bootstrap/bootstrap-v2-modal-plugin.html http://outofmemory.cn/bootstrap/tutor ...

  2. 云计算中auto-scaling 最早的来源

    什么是弹性?首先,整合计算资源,将计算资源池化,通过虚拟机按需使用计算资源;其次,按量计费,让用户能够根据使用量按月按时甚至按秒来进行付费. 不过,光有了这两条还不够.为什么?我举个例子: 很多做运维 ...

  3. php中ignore_user_abort函数的用法(定时)

    PHP中的ignore_user_abort函数是当用户关掉终端后脚本不停止仍然在执行,可以用它来实现计划任务与持续进程,下面会通过实例讨论ignore_user_abort()函数的作用与用法. i ...

  4. xml & < 需要转义

    写了个request2XML的方法,每当数据中有'<'.'&'符号时,封装的XML就无法解析.发现了XML里的CDATA属性,问题迎刃而解!在XML文档中的所有文本都会被解析器解析. 只 ...

  5. linux下如何关闭防火墙、查看当前的状态、开放端口

    从配置菜单关闭防火墙是不起作用的,索性在安装的时候就不要装防火墙查看防火墙状态:/etc/init.d/iptables status暂时关闭防火墙:/etc/init.d/iptables stop ...

  6. ThinkPHP Mongo驱动update方法支持upsert参数

    Mongo数据库update操作有一个相对于Mysql的关键特性,它可以使用upsert模式,当更新的数据不存在时,直接插入,但是ThinkPHP的Mongo驱动居然不支持这一特性,没办法,自力更生了 ...

  7. 【matlab】使用VideoReader提取视频的每一帧,不能用aviread函数~

    这个问题是matlab版本问题,已经不用aviread函数了~ VideoReader里面没有cdata这个函数! MATLAB不支持avireader了,而且没有cdata这个属性了,详情去官网ht ...

  8. Neo4j简单的样例

    系统环境: Ubuntu 04.10 x64 一:安装 下载最新版:neo4j-community-2.2.3-unix.tar.gz  解压 cd neo4j-community-2.2.3/bin ...

  9. laravel 模版引擎使用

    laravel 模版引擎以 @标签 开头,以 @end标签 结尾,常用有 foreach foreachelse if for while等 1)foreach 和 foreachelse 差不到,区 ...

  10. C++中的枚举变量

    至从C语言开始enum类型就被作为用户自定义分类有限集合常量的方法被引入到了语言当中,而且一度成为C++中定义编译期常量的唯一方法(后来在类中引入了静态整型常量).根据上面对enum类型的描述,有以下 ...