Could not create SSL/TLS secure channel.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dahipster
    Junior Member
    • Jul 2021
    • 3

    #1

    Could not create SSL/TLS secure channel.

    Hi all,

    Wonder if someone can please help a noob. I have been using the James Butler book 'Programming for Betfair' but I wonder if it's a bit out of date. When I run the program I get the following error but I have no idea what I am missing.

    An exception of type 'System.Net.WebException' occurred in System.dll but was not handled in user code

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

    If there is a handler for this exception, the program may be safely continued.

    The app loads the login window then breaks after I enter my username and password. The 2FA screen is not presented, but I have added this PC as a trusted device and also tried temporarily disabling 2FA (re-enabled now) to see if that was causing the issue.

    When Visual Studio breaks, it takes me to the penultimate line of this code:
    ===
    Private Function SendSportsReq(ByVal jsonString As String)
    Dim request As WebRequest = WebRequest.Create("https://api.betfair.com/exchange/betting/json-rpc/v1")

    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(jsonString)

    request.Method = "POST"
    request.ContentType = "application/json"
    request.ContentLength = byteArray.Length
    request.Headers.Add("X-Application: **MY KEY**")
    request.Headers.Add("X-Authentication: " & ssoid)

    Dim dataStream As Stream = request.GetRequestStream() <===
    dataStream.write(byteArray, 0, byteArray.Length)
    ====

    More information can be provided if it will help, but any advice would be greatly appreciated!
    Last edited by dahipster; 19-07-2021, 10:12 PM. Reason: tags added
  • darlorob
    Junior Member
    • Feb 2019
    • 5

    #2
    I am also getting intermittent SSL/TLS errors.

    .NET 5 application, no changes our end, worked perfectly until Friday.

    Response is:

    `The SSL connection could not be established. Received an unexpected EOF or 0 bytes from the transport stream.`

    This started on Friday night accross several endpoints - including PlaceOrder which has caused a lot of problems.

    If anyone figures out why it is happening pleaser let me know, I am 99.99% confident it is not our side, and it works most of the time (and always worked before).

    Comment

    • geoffw123
      Senior Member
      • Mar 2014
      • 250

      #3
      What version of TLS are you using ? It needs to be TLS version 1.2. One way to easily set this is to make sure you are using Dot Net framework 4.6 or later

      Comment

      • dahipster
        Junior Member
        • Jul 2021
        • 3

        #4
        Originally posted by geoffw123 View Post
        What version of TLS are you using ? It needs to be TLS version 1.2. One way to easily set this is to make sure you are using Dot Net framework 4.6 or later
        I am using .NET framework 4.8 according to the project properties, but have multiple versions installed. Should I get rid of versions pre 4.6 to ensure that there is no clash?
        Last edited by dahipster; 21-07-2021, 09:55 AM.

        Comment

        • WTPooh
          Member
          • May 2012
          • 88

          #5
          Add this line to your program:
          ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

          Comment

          • geoffw123
            Senior Member
            • Mar 2014
            • 250

            #6
            Hi
            Dot Net version 4.8 should be fine, you don't need to delete any older versions. Net 4.8 should give you TLS1.2 by default. The problem must lie elsewhere, but not sure what it is sorry. You can try WTPooh's suggestion as its quick and easy to do, but I suspect it wont help on your specific problem.

            Comment

            • dahipster
              Junior Member
              • Jul 2021
              • 3

              #7
              Originally posted by WTPooh View Post
              Add this line to your program:
              ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
              This seems to have worked, thanks very much!

              Comment

              • jsr84
                Junior Member
                • Nov 2021
                • 3

                #8
                this helped me too, thanks!

                Comment

                Working...
                X