cancel
Showing results for 
Search instead for 
Did you mean: 

Error on creditcard processing

Hi I am using Asp.net 3.5 framework, I had implemented Authorize.net work for credit card processing which was working fine last month but now It stopped working, I tried to debug code and getting this error

The underlying connection was closed: An unexpected error occurred on a send.

 

Here is code I am using:

 

Dim ApiLogin As String = "ABCD"
Dim TransactionKey As String = "1234"


Dim post_url As [String] = "https://secure2.authorize.net/gateway/transact.dll"


lblGrandTotal.Text = "1"
ExpDate = Regex.Split(hidExpDate.Value, "/")
If ExpDate.Length > 0 Then
Month = ExpDate(0)
Year = ExpDate(1).Remove(0, 2)
End If
'curExpDate = Month + "" + Year

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

post_values.Add("x_login", ApiLogin)
post_values.Add("x_tran_key", TransactionKey)
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", lblCC.Text)
'post_values.Add("x_card_num", "12345")
post_values.Add("x_card_code", lblAuth_Code.Text)
'post_values.Add("x_card_code", "027")
post_values.Add("x_exp_date", Month + "" + Year)

post_values.Add("x_amount", "2000")
post_values.Add("x_description", "")


post_values.Add("x_first_name", hidFName.Value)
post_values.Add("x_last_name", hidLName.Value)
post_values.Add("x_company", hidCompanyName.Value)

post_values.Add("x_address", lblAdd.Text)
post_values.Add("x_state", lblState.Text)
post_values.Add("x_zip", lblZipCode.Text)
post_values.Add("x_city", lblCity.Text)
post_values.Add("x_country", lblCntry.Text)


Dim post_string As [String] = ""

For Each post_value As KeyValuePair(Of String, String) In post_values
post_string += post_value.Key + "=" + HttpUtility.UrlEncode(post_value.Value) + "&"
Next
post_string = post_string.TrimEnd("&"c)

'Create an HttpWebRequest object to communicate with Authorize.net
Dim objRequest As HttpWebRequest = DirectCast(WebRequest.Create(post_url), HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentLength = post_string.Length
objRequest.ContentType = post_url

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

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls

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

 

 

   Please help me as i am getting this issue on Production.

 

smandola
Contributor
3 REPLIES 3

Hello @smandola

 

You will need to upgrade your platform to support TLS 1.2.  Another developer provided detailed instructions for asp.net here: https://community.developer.authorize.net/t5/Integration-and-Testing/TLS-1-2-Issue-in-Classic-ASP-en...

 

Richard

RichardH
Administrator Administrator
Administrator

I am getting below error
The underlying connection was closed: An unexpected error occurred on a receive.

Actually I made successful transaction after fixing issue on my windows7 machine, I added this line in authorize.net code
ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
and I changed my .net code framework to 4.0 and I have installed framework 4.6 and then my processing for credit card worked fine, BUT today when I tried to move that code on server,we are using Windows server 2008 Standard, I did same settings which I did on my windows7 machine but It's not working there, I am getting above error. I checked that updates were installed 1 week before in that server, Please help me with right solution asap as OUR PRODUCTION IS DOWN because of this issue.

I followed same instruction but stll it's not working.