I have some legacy VB.NET code that we use for our college's Foundation donation forms. As of yesterday they no longer work and I assume it's because I failed to address the TLS 1.0 -> TLS 1.2 issue? At any rate, what code do I have to add (in VB.NET) to get my forms to actually submit once again without receiving a "Received an unexpected EOF or 0 bytes from the transport stream" error. Thanks.
Code is the standard sample code that they used to provide here:
Dim post_url As String = "https://secure.authorize.net/gateway/transact.dll" Dim post_values As New Hashtable() 'API Login ID and Transaction Key post_values.Add("x_login", ConfigurationManager.AppSettings("AuthorizeNetLogin")) post_values.Add("x_tran_key", ConfigurationManager.AppSettings("AuthorizeNetTransactionKey")) ' Toggling between "TRUE" and "FALSE" for the "x_test_request" values is the equivalent to logging into "Mechant Login" and switching between "TEST" and "LIVE" modes. ' Changing the "x_test_request" value is much quicker than logging into the account, however. ' Note that submissions performed while in Test mode will not show up as a transaction in Authorize.net. ' After changing to LIVE mode, your transactions will show up. You'll have to use a real credit card though, not the 4111111111111111 test number. ' To find the transactions in LIVE mode, go to "Unsettled Transactions". Be sure to void your test transactions too (before that day's "settlement" time). post_values.Add("x_test_request", "FALSE") post_values.Add("x_version", "3.1") post_values.Add("x_type", "AUTH_CAPTURE") post_values.Add("x_delim_data", "TRUE") post_values.Add("x_delim_char", "|") post_values.Add("x_relay_response", "FALSE") post_values.Add("x_method", "CC") 'CUSTOMER INFO post_values.Add("x_card_num", Me.txtCardNumber.Text) post_values.Add("x_exp_date", Me.txtExpirationDate.Text) post_values.Add("x_card_code", Me.txtSecurityCode.Text) post_values.Add("x_description", Me.ddlScholarshipFund.SelectedItem.Text) post_values.Add("x_amount", strAmount) post_values.Add("x_first_name", Me.txtCardholdersFirstName.Text) post_values.Add("x_last_name", Me.txtCardholdersLastName.Text) post_values.Add("x_address", Me.txtCardholdersStreet.Text) post_values.Add("x_city", Me.txtCardholdersCity.Text) post_values.Add("x_state", Me.txtCardholdersState.Text) post_values.Add("x_zip", Me.txtCardholdersZip.Text) post_values.Add("x_ship_to_first_name", Me.txtFirstName.Text) post_values.Add("x_ship_to_last_name", Me.txtLastName.Text) post_values.Add("x_ship_to_address", Me.txtStreet.Text) post_values.Add("x_ship_to_city", Me.txtCity.Text) post_values.Add("x_ship_to_state", Me.txtState.Text) post_values.Add("x_ship_to_zip", Me.txtZip.Text) post_values.Add("x_email", Me.txtEmail.Text) post_values.Add("x_phone", Me.txtPhone.Text) post_values.Add("x_customer_ip", Request.UserHostAddress()) ' 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 field As DictionaryEntry In post_values post_string &= field.Key & "=" & HttpUtility.UrlEncode(field.Value) & "&" Next 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) ' check the response code and see if the transaction was approved ' 1 = Approved, 2 = Declined, 3 = Error, 4 = Held for Review If (response_array.GetValue(0) = 1) Then paymentSubmission = True Else Response.Redirect("donatenow_error.aspx?eid=" & response_array.GetValue(3)) End If
โ03-02-2018 12:36 PM
Hi
This would depend on the .NET framework version you are using and your server settings for TLS 1.2. You will need to have your application on .NET version which supports TLS 1.2.
Did you go through our support page for TLS 1.2 ?
Let us know if you have further questions.
Thanks
โ03-04-2018 02:49 AM
To begin, you should ensure Schannel is using TLS 1.2 with
using System; using System.Net; using System.IO; namespace howsMySSL { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; var response = WebRequest.Create("https://www.howsmyssl.com/a/check").GetResponse(); var responseData = new StreamReader(response.GetResponseStream()).ReadToEnd(); Response.Write(responseData); } } }
The API endpoint at https://secure.authorize.net/gateway/transact.dll is depecated. HttpWebRequest and HttpWebResponse are obsolete.
For such as small application, you may want to refactor with updated code.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(post_url), HttpWebRequest)
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New StreamReader(receiveStream, encode)
โ03-04-2018 04:44 AM