【转】D365 FO第三方访问https证书问题
生活随笔
收集整理的這篇文章主要介紹了
【转】D365 FO第三方访问https证书问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
D365FO采用https,第三方通過API調用的時候,客戶端不見得信任D365FO的證書,調用時候會報
基礎連接已關閉,發送時發生錯誤,調用堆棧如下:
?
1 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)2 at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)3 at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)4 at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)5 at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)6 at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)7 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)8 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)9 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 10 at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) 11 at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) 12 at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) 13 at System.Net.ConnectStream.WriteHeaders(Boolean async)?
從調用堆棧看,應該是跟SSL驗證有關系。
當然有時候還會直接報
基礎連接已經關閉: 未能為 SSL/TLS 安全通道建立信任關系
這個就更直接了。
網上有很多解決辦法,目的是讓https請求跳過客戶端對SSL證書的驗證。
?
1 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 2 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback( 3 (object caller, 4 X509Certificate certifacate, 5 X509Chain chain, 6 SslPolicyErrors erros) => { return true; }); 7 var request = HttpWebRequest.Create(url);?
這段代碼一定要放到HttpWebRequest之前,要不然回調的時候調不到方法。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
這一句也是必須的,D365的協議版本是Tls12,指定別的版本也不會跳過檢查。
總結
以上是生活随笔為你收集整理的【转】D365 FO第三方访问https证书问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 长江养老心享366是什么类型产品?收益怎
- 下一篇: 【转】.NET 自带的动态代理+Expr