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

Highlighted
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

0 Likes
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 125

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 

0 Likes
Highlighted
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.

 

0 Likes