Showing results for 
Search instead for 
Did you mean: 

Could not establish trust relationship for the SSL/TLS

We just had our site (hosted with Godaddy) migrated from a server that only supported TLS1.0 and 1.1 to a server that supports TSL1.0, 1.1, and 1.2.  The site was developed years ago using Visual Basic.  Unfortunatly, now when we try to submit a payment request, we get a "Could not create SSL/TLS secure channelerror message.  We did not make any changes within our code.  We are using a basic httpwebrequest object to communicate with  Is there a change that I need to make within our code to instruct the connection to be made using TSL1.2 instead of TSL1.0 or TSL1.1?


This is the code we are currently using to submit our request to


Dim post_url As String
post_url = ""

Dim ccnum As String = "", _
ccexp As String = "", _
firstname As String = "", _
lastname As String = "", _
name As String, _
orderid As Integer = subscriberidfld.Value

Dim address2 As String = "", _
shipaddress2 As String = "", _
fax As String = "", _
shipfax As String = ""

ccexp = ccmonthdd.SelectedValue & Right(ccyeardd.SelectedValue, 2)
Catch ex As Exception
ccexp = "0000"
End Try

ccnum = cc1txt.Text.Trim & cc2txt.Text.Trim & cc3txt.Text.Trim & cc4txt.Text.Trim
Catch ex As Exception

End Try

firstname = nametxt.Text.Trim
Catch ex As Exception
firstname = Nothing
End Try
lastname = lastnametxt.Text.Trim
Catch ex As Exception
lastname = Nothing
End Try

If Not name Is Nothing Then
firstname = name(0)
lastname = name(1)
If name.Length = 3 Then
lastname = name(1) & " " & name(2)
End If
If name.Length = 4 Then
lastname = name(1) & " " & name(2) & " " & name(3)
End If
If name.Length = 5 Then
lastname = name(1) & " " & name(2) & " " & name(3) & " " & name(4)
End If
End If

Dim post_values As New Generic.Dictionary(Of String, String)

'check the subscriber_num_track table for the current year and current month
'if number of signups for the month < 30, then mark subscriber as a SSM subscriber and use SSM account

'the API Login ID and Transaction Key must be replaced with valid values

Dim SQLConn As New SqlConnection
Dim sql As String = ""
Dim is_ssm_sub As Integer = 0, _
is_ep_sub As Integer = 0, _
loginkey As String = "XXXXXXXX3BgV", _
trankey As String = "XXXXXXXXXXXXXHK2"

loginkey = "XXXXXXXX3BgV"

is_ssm_sub = 1
is_ep_sub = 0

post_values.Add("x_login", loginkey)
post_values.Add("x_tran_key", trankey)

post_values.Add("x_test_request", "FALSE")

post_values.Add("x_delim_data", "TRUE")
post_values.Add("x_delim_char", "|")
post_values.Add("x_relay_response", "FALSE")

post_values.Add("x_type", "AUTH_CAPTURE")
post_values.Add("x_method", "CC")
post_values.Add("x_card_num", ccnum)
post_values.Add("x_exp_date", ccexp)
'security code
post_values.Add("x_card_code", ccsecnumtxt.Text.Trim)

Dim totalcost As Integer = CInt(totallbl.Text.Trim.Replace("$", ""))

post_values.Add("x_amount", totalcost)
post_values.Add("x_invoice", orderid.ToString)
post_values.Add("x_description", "Solved Social Media Order #:" & orderid.ToString)

post_values.Add("x_first_name", firstname)
post_values.Add("x_last_name", lastname)
post_values.Add("x_address", addresstxt.Text.Trim & " " & address2)
post_values.Add("x_city", citytxt.Text.Trim)
post_values.Add("x_state", statedropdown.SelectedValue)
post_values.Add("x_zip", ziptxt.Text.Trim)
' Additional fields can be added here as outlined in the AIM integration
' guide at:

' This section takes the input fields and converts them to the proper format
' for an http post. For example: "x_login=username&x_tran_key=a1B2c3D4"
Dim post_string As String = ""

For Each kvp As Generic.KeyValuePair(Of String, String) In post_values
Console.WriteLine("Key = {0}, Value = {1}", _
kvp.Key, kvp.Value)
post_string = post_string & kvp.Key & "=" & Server.UrlEncode(kvp.Value) & "&"
Next kvp

post_string = Left(post_string, Len(post_string) - 1)

' create an HttpWebRequest object to communicate with
Dim objRequest As HttpWebRequest = CType(WebRequest.Create(post_url), HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentLength = post_string.Length
objRequest.ContentType = "application/x-www-form-urlencoded"

' post data is sent as a stream
Dim myWriter As StreamWriter = Nothing
myWriter = New StreamWriter(objRequest.GetRequestStream())

' returned values are returned as a stream, then read into a string
Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
Dim responseStream As New StreamReader(objResponse.GetResponseStream())
Dim post_response As String = responseStream.ReadToEnd()

' the response string is broken into an array
Dim response_array As Array = Split(post_response, post_values("x_delim_char"), -1)



I have highlighted the code that the server errors on.  This is the error back from the server:

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

Source Error: 

Line 768:        ' post data is sent as a stream
Line 769:        Dim myWriter As StreamWriter = Nothing
Line 770:        myWriter = New StreamWriter(objRequest.GetRequestStream())Line 771:        myWriter.Write(post_string)
Line 772:        myWriter.Close()

Source File: G:\PleskVhosts\\httpdocs\pay_web.aspx.vb    Line: 770 

Stack Trace: 

[WebException: The request was aborted: Could not create SSL/TLS secure channel.]
   System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) +916
   System.Net.HttpWebRequest.GetRequestStream() +13
   pay_web.submitpmt() in G:\PleskVhosts\\httpdocs\pay_web.aspx.vb:770
   pay_web.continuebtn2_Click(Object sender, EventArgs e) in G:\PleskVhosts\\httpdocs\pay_web.aspx.vb:607
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9815014
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639


Any assistance is greatly apprciated!


Thank you,



That code can and should be simplified.  The new API endpoint at accepts XML and you would create the server object with:

Set httpRequest = Server.CreateObject("MSXML2.XMLHTTP.6.0")


Powered by -
Certified developers
Trusted Contributor

We also have similar code and the code fails at "stream = webRequest.GetRequestStream();"

This code is in Dynamics AX 2009. I am testing using "" API. I signed up on the and got the test login and transaction key.



 WebRequest = System.Net.WebRequest::Create(ccAdn.HostAddress);

            stream = webRequest.GetRequestStream();
            streamWriter = new System.IO.StreamWriter(stream);

            webResponse = webRequest.GetResponse();


Any ideas how to fix this?



I have the exact issue as the person who posted this error.  I don't understand your response.  Can you elaborate? 

as was suggested in another post out here, this worked.  I'm using the same code as you, going to, and now all is well.

Const _Tls12 As SslProtocols = DirectCast(&HC00, SslProtocols)

Const Tls12 As SecurityProtocolType = DirectCast(_Tls12, SecurityProtocolType)

ServicePointManager.SecurityProtocol = Tls12


To make this even simpler, I just added the following line to my code and it worked.


ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12