Skip to content

Commit c0c275e

Browse files
authored
Merge pull request AuthorizeNet#249 from cforbesywam/future
Future - Fix for Issue 234 - TLS 1.2 must be set before HttpWebRequest is created
2 parents f275012 + 542b845 commit c0c275e

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Authorize.NET/Util/HttpUtility.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ public static ANetApiResponse PostData<TQ, TS>(AuthorizeNet.Environment env, TQ
3939
throw new ArgumentNullException("request");
4040
}
4141
//Logger.debug(string.Format("MerchantInfo->LoginId/TransactionKey: '{0}':'{1}'->{2}",
42-
//request.merchantAuthentication.name, request.merchantAuthentication.ItemElementName, request.merchantAuthentication.Item));
43-
44-
var postUrl = GetPostUrl(env);
42+
//request.merchantAuthentication.name, request.merchantAuthentication.ItemElementName, request.merchantAuthentication.Item));
43+
44+
// Set Tls to Tls1.2
45+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
46+
47+
var postUrl = GetPostUrl(env);
4548
var webRequest = (HttpWebRequest) WebRequest.Create(postUrl);
4649
webRequest.Method = "POST";
4750
webRequest.ContentType = "text/xml";
@@ -67,9 +70,6 @@ public static ANetApiResponse PostData<TQ, TS>(AuthorizeNet.Environment env, TQ
6770
String responseAsString = null;
6871
Logger.debug(string.Format("Retreiving Response from Url: '{0}'", postUrl));
6972

70-
// Set Tls to Tls1.2
71-
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
72-
7373
using (var webResponse = webRequest.GetResponse())
7474
{
7575
Logger.debug(string.Format("Received Response: '{0}'", webResponse));

Authorize.NET/Utility/HttpXmlUtility.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public ANetApiResponse Send(ANetApiRequest apiRequest) {
5454
//Authenticate it
5555
AuthenticateRequest(apiRequest);
5656

57+
// Set Tls to Tls1.2
58+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
59+
5760
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_serviceUrl);
5861
webRequest.Method = "POST";
5962
webRequest.ContentType = "text/xml";
@@ -74,9 +77,6 @@ public ANetApiResponse Send(ANetApiRequest apiRequest) {
7477
serializer.Serialize(writer, apiRequest);
7578
writer.Close();
7679

77-
// Set Tls to Tls1.2
78-
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
79-
8080
// Get the response
8181
WebResponse webResponse = webRequest.GetResponse();
8282

0 commit comments

Comments
 (0)