title: Get Paypal response TLS 1.2 .Net Framework 4.0
body: <p>We have a website that uses .Net Framework 4.0 and IIS 7.
  After the lasts updates of Paypal our IPN handler is not working any more. We had this error:
  <a href="https://stackoverflow.com/questions/34939523/the-request-was-aborted-could-not-create-ssl-tls-secure-channel-sandbox-account/35022980">The request was aborted: Could not create SSL/TLS secure channel sandbox account</a>
  So as we are using .Net Framework 4.0 We added the next line:</p>
  
  <pre><code>ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
  </code></pre>
  
  <p>Now we have another error: 
  The underlying connection was closed: An unexpected error occurred on a send.</p>
  
  <p>The class that handles the response is based in this example:
  <a href="https://mvcsamples.svn.codeplex.com/svn/trunk/Kona.Web/Controllers/PayPalController.cs" rel="nofollow noreferrer">https://mvcsamples.svn.codeplex.com/svn/trunk/Kona.Web/Controllers/PayPalController.cs</a></p>
  
  <p>After adding the before line now looks like this:</p>
  
  <pre><code>private string GetPayPalResponse(Dictionary&lt;string, string&gt; formVals, bool useSandbox)
  {
          string paypalUrl = useSandbox ? "https://www.sandbox.paypal.com/cgi-bin/webscr"
              : "https://www.paypal.com/cgi-bin/webscr";
  
          ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
  
          HttpWebRequest req = (HttpWebRequest)WebRequest.Create(paypalUrl);
  
          // Set values for the request back
          req.Method = "POST";
          req.ContentType = "application/x-www-form-urlencoded";
  
          byte[] param = Request.BinaryRead(Request.ContentLength);
          string strRequest = Encoding.ASCII.GetString(param);
  
          StringBuilder sb = new StringBuilder();
          sb.Append(strRequest);
  
          foreach (string key in formVals.Keys)
          {
              sb.AppendFormat("&amp;{0}={1}", key, formVals[key]);
          }
          strRequest += sb.ToString();
          req.ContentLength = strRequest.Length;
  
          //for proxy
          //WebProxy proxy = new WebProxy(new Uri("http://urlort#");
          //req.Proxy = proxy;
          //Send the request to PayPal and get the response
          string response = "";
          using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)) 
          {
              streamOut.Write(strRequest);
              streamOut.Close(); linea = 10;
              using (StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
              {
                  response = streamIn.ReadToEnd();
              }
          }
          return response;
   }
  </code></pre>
  
  <p>The exception is raised in this line:</p>
  
  <pre><code>using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
  </code></pre>
  
  <p>We are not sure if we could make Paypal work with .NET Framework 4.0. There is said that is possible using the line we added. But is not working. Maybe there are more changes needed to be done in the code or in the IS 7. But we couldn't find examples.</p>
  
  <p>Thank you for the help.</p>
  
  <p>EDIT:</p>
  
  <p>I almost forgot to mention that the project is developed using Visual Studio 2010. Where there's not the .NET Framework 4.5.</p>
  
  <p>EDIT 2:</p>
  
  <p>I investigated the issue and I found that our server Windows Server 2008 didn't support TLS 1.2 (look at the table):
  <a href="https://blogs.msdn.microsoft.com/kaushal/2011/10/02/support-for-ssltls-protocols-on-windows/" rel="nofollow noreferrer">https://blogs.msdn.microsoft.com/kaushal/2011/10/02/support-for-ssltls-protocols-on-windows/</a>
  But after that I found a new update of this year 2016 for all versions of SQL Server.
  <a href="https://blogs.msdn.microsoft.com/sqlreleaseservices/tls-1-2-support-for-sql-server-2008-2008-r2-2012-and-2014/" rel="nofollow noreferrer">https://blogs.msdn.microsoft.com/sqlreleaseservices/tls-1-2-support-for-sql-server-2008-2008-r2-2012-and-2014/</a>
  <a href="http://blogs.sqlsentry.com/aaronbertrand/tls-1-2-support-read-first/" rel="nofollow noreferrer">http://blogs.sqlsentry.com/aaronbertrand/tls-1-2-support-read-first/</a></p>
  
  <p>But at the end my boss for some reasons decided not to update the server using the new update or using the register method. </p>
  
  <p>So I can't prove any solution tosolve the problem. Sorry for the trouble.</p>