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

MGroupGeoff
New Member
3 0 0

My code which worked fine in July 2018 is no longer working. It produces the error "The request was aborted: Could not create SSL/TLS secure channel."

 

Heres my code:

 

    Public Function ShopifyInterface(apiString As String, verb As String, Optional JSON As String = "") As String

        apiString = "shop.json"

        Dim url As String = "https://{Shop}.myshopify.com/" & apiString
        Dim req As HttpWebRequest = WebRequest.Create(url)
        req.Method = verb
        req.ContentType = "application/json"
        req.Credentials = GetCredential(url)
        req.PreAuthenticate = True
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

        If verb = "POST" Or verb = "PUT" Then
            Dim requestStream As Stream = req.GetRequestStream()
            Dim postBytes As Byte() = Encoding.ASCII.GetBytes(JSON)
            requestStream.Write(postBytes, 0, postBytes.Length)
            requestStream.Close()
        End If

        Dim failed As Boolean
        Try
            Using resp As HttpWebResponse = req.GetResponse()
                Select Case verb
                    Case "POST"
                        If resp.StatusCode <> HttpStatusCode.Created Then failed = True
                    Case "GET"
                        If resp.StatusCode <> HttpStatusCode.OK Then failed = True
                End Select

                If failed Then
                    Dim message As String = String.Format("Call failed. Received HTTP {0}", resp.StatusCode)
                    Throw New ApplicationException(message)
                End If
                Dim sr As StreamReader = New StreamReader(resp.GetResponseStream())
                Return sr.ReadToEnd()
            End Using
        Catch ex As WebException
            Using oStream As Stream = ex.Response.GetResponseStream()
                Using reader As New StreamReader(oStream)
                    Dim message As String = reader.ReadToEnd()
                    Console.WriteLine(message)
                    Return message
                End Using
            End Using
        End Try

    End Function

Any ideas

Replies 3 (3)
hassain
Shopify Staff (Retired)
623 104 154

Hey @MGroupGeoff ,

 

The error message of "The request was aborted: Could not create SSL/TLS secure channel." is definitely not an error message coming from Shopify, it appears to be coming from Visual Basic .NET

 

From a quick Google search, it appears that this error occurs because the URL you are trying to call requires TLS 1.1 or TLS 1.2, and to enable either of these things you need to set the security-protocol with ServicePointManager.SecurityProtocol: (I.e. : ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 ). https://stackoverflow.com/questions/46825387/vb-net-the-request-was-aborted-could-not-create-ssl-tls...

 

In any case, since this error does not come from or relate specifically to Shopify so perhaps other communities more specific to VB .NET might be more helpful for troubleshooting here. 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

KerryR
New Member
1 0 0

Your message saved me

    Dim req As HttpWebRequest = WebRequest.Create(url)        req.Method = verb
        req.ContentType = "application/json"        req.Credentials = GetCredential(url)        req.PreAuthenticate = True
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

It took days and I finally got it
I moved
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
before
Dim req As HttpWebRequest = WebRequest.Create(url)

(Although I was using c#)
but moving it above worked.

 

creigmalta
New Member
4 0 0

The error is generic and there are many reasons why the SSL/TLS negotiation may fail. ServicePointManager.SecurityProtocol property selects the version of the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocol to use for new connections; existing c# connections aren't changed. Make sure the ServicePointManager settings are made before the HttpWebRequest is created, else it will not work. Also, you have to enable other security protocol versions to resolve this issue:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
SecurityProtocolType.Tls
SecurityProtocolType.Tls11
SecurityProtocolType.Ssl3;

//createing HttpWebRequest after ServicePointManager settings
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://google.com/api/")

If you create HttpWebRequest before the ServicePointManager settings it will fail and shows the error message.