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 channel" error message. We did not make any changes within our code. We are using a basic httpwebrequest object to communicate with Authorize.net. 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 Authorize.net
Dim post_url As String
post_url = "https://secure.authorize.net/gateway/transact.dll"
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 = ""
Try
ccexp = ccmonthdd.SelectedValue & Right(ccyeardd.SelectedValue, 2)
Catch ex As Exception
ccexp = "0000"
End Try
Try
ccnum = cc1txt.Text.Trim & cc2txt.Text.Trim & cc3txt.Text.Trim & cc4txt.Text.Trim
Catch ex As Exception
End Try
Try
firstname = nametxt.Text.Trim
Catch ex As Exception
firstname = Nothing
End Try
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 TO SEE WHICH AUTHORIZE.NET ACCOUNT THIS SHOULD GO TO, SSM OR EP --------------
'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 authorize.net 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"
trankey = "XXXXXXXXXXXXXHK2"
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: http://developer.authorize.net
' 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 Authorize.net
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())
myWriter.Write(post_string)
myWriter.Close()
' 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()
responseStream.Close()
' 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()
|
02-08-2018 12:31 PM
That code can and should be simplified. The new API endpoint at https://api.authorize.net/xml/v1/request.api accepts XML and you would create the server object with:
Set httpRequest = Server.CreateObject("MSXML2.XMLHTTP.6.0")
02-09-2018 04:35 AM
We also have similar code and the code fails at "stream = webRequest.GetRequestStream();"
This code is in Dynamics AX 2009. I am testing using "https://test.authorize.net/gateway/transact.dll" API. I signed up on the developer.authorize.net and got the test login and transaction key.
WebRequest = System.Net.WebRequest::Create(ccAdn.HostAddress);
WebRequest.set_Method('POST');
WebRequest.set_ContentLength(strlen(parmList));
WebRequest.set_ContentType('application/x-www-form-urlencoded');
stream = webRequest.GetRequestStream();
streamWriter = new System.IO.StreamWriter(stream);
streamWriter.Write(parmList);
streamWriter.Close();
webResponse = webRequest.GetResponse();
Any ideas how to fix this?
Thanks
Daljeet
02-14-2018 12:51 PM
I have the exact issue as the person who posted this error. I don't understand your response. Can you elaborate?
03-20-2018 08:05 AM
as was suggested in another post out here, this worked. I'm using the same code as you, going to authorize.net, and now all is well.
Const _Tls12 As SslProtocols = DirectCast(&HC00, SslProtocols)
Const Tls12 As SecurityProtocolType = DirectCast(_Tls12, SecurityProtocolType)
ServicePointManager.SecurityProtocol = Tls12
03-20-2018 09:08 AM
To make this even simpler, I just added the following line to my code and it worked.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
03-22-2018 08:54 AM