[C#] 於HTTP request默認所有SSL cert有效

最近公司上了新project, 為了檢查其穩定性, 須要每日定期檢查.為了方便自己工作, 便寫了一個工具去每日檢查網作運作. 說到底, 其實就是推一個HTTP request 去, 檢查其結果和是否有獨有的HTML, 以確保內容的rendering 沒有問題.

但在測試場地時, 見到其Cert 沒有註冊, 不能測試. 結果出了絕招, override 了CertValidation 的callback, 從而令其默認所有cert 都是valid 的.

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) =>
            {
                return true;
            };

但這一種危險設定須要小心進行, 以確保沒有security issue.

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.