Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vb.net

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 request was aborted: Could not create SSL/TLS secure channel.

    'ServicePointManager.Expect100Continue = False
    'ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls

    Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)

    Dim ErrMsg As String = String.Empty

    Try

        Dim response As WebResponse = request.GetResponse()

        Using responseStream As Stream = response.GetResponseStream()
            Dim reader As New StreamReader(responseStream, Encoding.UTF8)

            Return reader.ReadToEnd()
        End Using
    Catch ex As WebException

        ErrMsg = ex.Message.ToString
        MsgBox(ErrMsg)

        Dim errorResponse As WebResponse = ex.Response
        Using responseStream As Stream = errorResponse.GetResponseStream()
            Dim reader As New StreamReader(responseStream, Encoding.GetEncoding("utf-8"))
            ' log errorText
            Dim errorText As [String] = reader.ReadToEnd()
        End Using
        Throw
    End Try

This is my code and I'm using VS2015 and Windows 10.

All help are really appreciated. TIA

like image 760
wysiwyg327 Avatar asked Oct 19 '17 08:10

wysiwyg327


People also ask

Why the request was aborted could not create SSL TLS secure channel?

The error “The request was aborted: Could not create SSL/TLS secure channel.” can happen during any download HTTP request. This error generally will correspond to firewalls, proxies or DNS filtering blocking the connection or an SSL/TLS cipher misconfiguration.

Can't create SSL TLS secure channel IIS?

However, the "Could not create SSL/TLS secure channel" error usually means that there's something wrong with the server certificate, e.g. the certificate is for a different hostname, or otherwise invalid, or not trusted etc.


1 Answers

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?
like image 174
MatSnow Avatar answered Nov 15 '22 07:11

MatSnow