VB. NET: The request was aborted: Could not create SSL/TLS secure channel

前端 未结 2 1627
庸人自扰
庸人自扰 2021-01-15 16:52

I have an application coded in VB.net that has this method of accessing Webservice, i have this error and after searching fixes i still have no luck.

Error: The requ

相关标签:
2条回答
  • 2021-01-15 17:47

    I'm going to add something here in case it helps others. I have to support some legacy code that is written in VB.Net and targets .NET Framework 4.6.1. The same piece of code runs in both an .exe, and in IIS as a web page.

    In the website, this call:

    Dim dataStream As Stream = request.GetRequestStream()
    

    would throw this exception

    The request was aborted: Could not create SSL/TLS secure channel.
    

    but it worked fine in the .exe.

    Forcing the TLS protocol fixed it in the website.

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
    

    Of course if the host ever deems TLS 1.2 unworthy I'll have to fix/recompile/redeploy, but it solved the error for now.

    0 讨论(0)
  • 2021-01-15 17:54

    Obviously the URL you're calling requires TLS 1.1 or TLS 1.2.

    You can enable TLS 1.1 or TLS 1.2 by setting the security-protocol with ServicePointManager.SecurityProtocol:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
    

    .NET 4.0 supports up to TLS 1.0 while .NET 4.5 or higher supports up to TLS 1.2
    For reference:

    • Default SecurityProtocol in .NET 4.5
    • Are there .NET implementation of TLS 1.2?
    0 讨论(0)
提交回复
热议问题