title: TLS 1.2 still not working with Unity 2018.2.0b3
body: <p>In <em>Unity 2018.2.0b3</em> release note mentioned as TLS 1.2 is added and working with all platforms. When we tested it, it still isn't working and throws some errors. The same code is working in <em>.Net application 4.5 framework</em>.</p>
  
  <blockquote>
    <p>Error: SecureChannelFailure (One or more errors occurred.) UnityEngine.Debug:Log(Object) CheckTLS:GetAuth() (at Assets/CheckTLS.cs:31) UnityEngine.EventSystems.EventSystem:Update()  </p>
  </blockquote>
  
  <p>Is there any dependency or any specific settings to do so, please do help to resolve this issue.</p>
  
  <pre><code>using Newtonsoft.Json.Linq;
  using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Net;
  using System.Text;
  using System.Web;
  
  namespace SmartMeterCalculations
  {
      class Authentication
      {
          public string AccessToken;
          public string TokenType;
          public string ExpiresIn;
          public DateTime ExpiryDate;
          public string Scope;
          public string Ext_Attr_Enhancer;
          public string JTI;
      }
  
      class Reading
      {
          public DateTime Date;
          public Double Value;
      }
  
      class APICalls
      {
          public static Authentication AuthenticateAPI(
              string OauthURL,
              string ClientId,
              string ClientSecret)
          {
              Authentication authentication = null;
              ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
                                         SecurityProtocolType.Tls11 |
                                         SecurityProtocolType.Tls12;
  
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(OauthURL);
  
              request.Method = "POST";
              request.ContentType = "application/x-www-form-urlencoded";
              request.Accept = "application/json";
              WebProxy webProxy = new WebProxy("http://proxy:8080");
  
              request.Proxy = webProxy;
  
              string parameters = "";
              parameters = "response_type=token";
              parameters += "&amp;grant_type=client_credentials";
              parameters += "&amp;client_id=sb-c4e-eds-clone-showcase!b1900%7cc4e-eds-test!b462";// + Convert.ToBase64String(Encoding.Default.GetBytes(ClientId));// HttpUtility.UrlEncode(ClientId);
              parameters += "&amp;client_secret=2hxc7EmQyArDoO%2f7dSgJJXnPgpg%3d";// + Convert.ToBase64String(Encoding.Default.GetBytes(ClientSecret));// HttpUtility.UrlEncode(ClientSecret);
  
              byte[] byteArray = Encoding.ASCII.GetBytes(parameters);
              request.ContentLength = byteArray.Length;
  
              Stream dataStream = request.GetRequestStream();
              dataStream.Write(byteArray, 0, byteArray.Length);
              dataStream.Close();
  
              WebResponse response = request.GetResponse();
              Console.WriteLine(((HttpWebResponse)response).StatusCode);
              Console.WriteLine(((HttpWebResponse)response).StatusDescription);
  
              dataStream = response.GetResponseStream();
  
              StreamReader reader = new StreamReader(dataStream);
              string responseFromServer = reader.ReadToEnd();
              Console.WriteLine(responseFromServer);
  
              reader.Close();
              dataStream.Close();
              response.Close();
  
              JObject data = JObject.Parse(responseFromServer);
  
              authentication = new Authentication();
              authentication.AccessToken = data["access_token"].ToString();
              authentication.TokenType = data["token_type"].ToString();
              authentication.ExpiresIn = data["expires_in"].ToString();
              authentication.Scope = data["scope"].ToString();
              authentication.Ext_Attr_Enhancer = data["ext_attr"]["enhancer"].ToString();
              authentication.JTI = data["jti"].ToString();
  
              DateTime dtExpire = DateTime.Now;
              dtExpire = dtExpire.AddSeconds(int.Parse(authentication.ExpiresIn));
              authentication.ExpiryDate = dtExpire;
  
              return authentication;
          }
  
          public static void updateReadings(
              string BearerToken,
              string MeterReadingsURL,
              string xmlBody)
          {
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(MeterReadingsURL);
  
              request.Method = "POST";
              request.ContentType = "application/xml";
              request.Accept = "application/xml";
              request.Headers.Add("Authorization", "Bearer " + BearerToken);
  
              byte[] bytes = Encoding.UTF8.GetBytes(xmlBody);
              request.ContentLength = bytes.Length;
  
              Stream dataStream = request.GetRequestStream();
              dataStream.Write(bytes, 0, bytes.Length);
              dataStream.Close();
  
              WebResponse response = request.GetResponse();
              Console.WriteLine(((HttpWebResponse)response).StatusCode);
              Console.WriteLine(((HttpWebResponse)response).StatusDescription);
  
              dataStream = response.GetResponseStream();
  
              StreamReader reader = new StreamReader(dataStream);
              string responseFromServer = reader.ReadToEnd();
              Console.WriteLine(responseFromServer);
  
              reader.Close();
              dataStream.Close();
              response.Close();
  
              Console.WriteLine(responseFromServer);
          }
  
          public static string getReadingBodyString(
              string MeterUUID,
              string TypeName,
              List&lt;Reading&gt; lstIntervalReadings)
          {
              string strReadings = "";
  
              //strReadings += "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n";
              strReadings += "&lt;msg:RequestMessage xmlns:msg=\"http://iec.ch/TC57/2011/schema/message\"&gt;\n";
  
              strReadings += "\t&lt;msg:Header&gt;\n";
              strReadings += "\t\t&lt;msg:Verb&gt;create&lt;/msg:Verb&gt;\n";
              strReadings += "\t\t&lt;msg:Noun&gt;MeterReadings&lt;/msg:Noun&gt;\n";
              strReadings += "\t&lt;/msg:Header&gt;\n";
  
              strReadings += "\t&lt;msg:Payload&gt;\n";
              strReadings += "\t\t&lt;m:MeterReadings xmlns:m=\"http://iec.ch/TC57/CIM-c4e#\"&gt;\n";
              strReadings += "\t\t\t&lt;m:MeterReading&gt;\n";
              strReadings += "\t\t\t\t&lt;m:IntervalBlocks&gt;\n";
  
              foreach (Reading intervalReading in lstIntervalReadings)
              {
                  strReadings += "\t\t\t\t\t&lt;m:IntervalReadings&gt;\n";
                  strReadings += "\t\t\t\t\t\t&lt;m:timeStamp&gt;" + TimeZone.CurrentTimeZone.ToUniversalTime(intervalReading.Date).ToString("o") + "&lt;/m:timeStamp&gt;\n";
                  strReadings += "\t\t\t\t\t\t&lt;m:value&gt;" + Math.Round(intervalReading.Value, 3) + "&lt;/m:value&gt;\n";
                  strReadings += "\t\t\t\t\t&lt;/m:IntervalReadings&gt;\n";
              }
  
              strReadings += "\t\t\t\t\t&lt;m:ReadingType ref=\"" + TypeName + "." + MeterUUID + "\"/&gt;\n";
  
              strReadings += "\t\t\t\t&lt;/m:IntervalBlocks&gt;\n";
  
              strReadings += "\t\t\t\t&lt;m:Meter&gt;\n";
              strReadings += "\t\t\t\t\t&lt;m:mRID&gt;" + MeterUUID + "&lt;/m:mRID&gt;\n";
              strReadings += "\t\t\t\t&lt;/m:Meter&gt;\n";
  
              strReadings += "\t\t\t&lt;/m:MeterReading&gt;\n";
              strReadings += "\t\t&lt;/m:MeterReadings&gt;\n";
              strReadings += "\t&lt;/msg:Payload&gt;\n";
              strReadings += "&lt;/msg:RequestMessage&gt;";
  
              strReadings = strReadings.Replace("\t", "");
              strReadings = strReadings.Replace("\n", "");
  
              return strReadings;
          }
      }
  }
  
      public void GetAuth()
      {
          string oAuthUrl = "https://c4e-showcase-account.authentication.sap.hana.ondemand.com/oauth/token";
          string clientId = "sb-c4e-eds-clone-showcase!b1900|c4e-eds-test!b462";
          string clientSecret = "2hxc7EmQyArDoO/7dSgJJXnPgpg=";
  
          try
          {
              Authentication authentication = APICalls.AuthenticateAPI(oAuthUrl, clientId, clientSecret);
          }
          catch(Exception ex)
          {
              Debug.Log(ex.Message);
          }
  
      }
  </code></pre>