2022年2月28日 星期一

[除錯] 無法建立 SSL/TLS 的安全通道

問題:

無法建立 SSL/TLS 的安全通道

收到來自傳輸資料流的未預期 EOF 或 0 個位元組


參考:

SecurityProtocolType 列舉

CA5386:避免將 SecurityProtocolType 值寫入程式碼


HttpWebRequest GetResponse()出現"要求已經中止: 無法建立 SSL/TLS 的安全通道"錯誤

[C#] 無法建立 SSL/TLS 的安全通道。解決方法

[VB.NET]加入HTTPS的服務參考遇到的問題

【原創】C# API 未能創建 SSL/TLS 安全通道 問題解決

要求已經中止: 無法建立 SSL/TLS 的安全通道。

HttpWebRequest GetResponse()出現"要求已經中止: 無法建立 SSL/TLS 的安全通道"錯誤

【茶包射手日記】.NET 3.5 TLS 1.2 踩雷記

.NET Framework 3.5 and TLS 1.2


解決C#呼叫有ssl憑證問題的網站出現遠端憑證是無效的錯誤問題

呼叫有ssl憑證問題的網站出現遠端憑證是無效的錯誤問題

ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;

private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)

{

    //// trust any certificate!!!

    //System.Console.WriteLine("Warning, trust any certificate");

    //return true;

            

    if (error == SslPolicyErrors.None)

    {

        return true;

    }

    var request = sender as HttpWebRequest;

    if (request != null)

    {

        var result = (request.RequestUri.Host == "11x.x.x.x" || request.RequestUri.Host == "192.16x.x.x");

        return result;

    }

    return false; 

}

CA5359: Do not disable certificate validation

AuthenticationException: Authentication failed, see inner exception. Win32Exception: 接收到的訊息超出預期或格式不正確。WebException: 要求已經中止: 無法建立 SSL/TLS 的安全通道。

System.Net.WebException: 要求已經中止: 無法建立 SSL/TLS 的安全通道 錯誤的另一種可能性2018-10-19



公開WebService:

政府資料開放平臺資料集清單

ListPriceWebService_NaturalGas

ListPriceWebService


解決:Winform .net 3.5

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;


//動態調用webservices Url

string url = "https://vipmember.tmtd.cpc.com.tw/OpenData/ListPriceWebService.asmx";


//無參數調用

object result1 = WebServiceHelper.InvokeWebService(url, "getCPCAviationFuelListPrice", null);          dataGridView1.DataSource = ((DataSet)result1).Tables[0];