我想从Xamarin.Forms使用TLS1.2发送POST事务,但我看到他们到达服务器作为TLS 1.1。不能发送TLS 1.2与Xamarin.Forms和VisualStudio 2017
我已经配置的Android选项:
HttpClient的impletemtation为的Android
SSL/TLS实现为本地TLS 1.2+
我实施和VisualStudio的2017年执行,并使用模拟器中的Android 6.0。
关于代码,我设置一些环境变量:
using (HttpClient client = new HttpClient())
or
using (HttpClient client = new HttpClient(new NativeMessageHandler()))
or
using (HttpClient client = new HttpClient(new Xamarin.Android.Net.AndroidClientHandler()))
{
try
{
HttpResponseMessage responseHttp = await client.PostAsync(new Uri(new Uri(Constants.ApiBaseUrl), "authorize"), content);
...
凡Constants.ApiBaseUrl包含一个URL以https:// <>格式
System.Environment.SetEnvironmentVariable("MONO_TLS_PROVIDER", "btls");
System.Environment.SetEnvironmentVariable("XA_TLS_PROVIDER", "btls");
System.Environment.SetEnvironmentVariable("XA_HTTP_CLIENT_HANDLER_TYPE", "Xamarin.Android.Net.AndroidClientHandler");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
最后,POST与发送。
的问题是,当POST发送我没有任何异常,但在我的服务器我使用Wireshark看到作为交易:
HttpWebRequest httpWebRequest = WebRequest.CreateHttp(new Uri(new Uri(Constants.ApiBaseUrl), "authorize"));
httpWebRequest.Method = "POST";
httpWebRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
Stream sw = httpWebRequest.GetRequestStream();
sw.Write(contentByte, 0, contentByte.Length);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
带和不使用我自己的证书:
httpWebRequest.ClientCertificates = cryptoSvc.x509HostCertificates;
在这种情况下,如果我用
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
我得到的异常
RestService-SendJsonDataAsync ERROR: Error: SecureChannelFailure
(**Ssl error:100000f0:SSL routines:OPENSSL_internal:UNSUPPORTED_PROTOCOL**
at /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/external/boringssl/ssl/handshake_client.c:808)
没有该行它也为到达TLS1.1。
有没有人有任何想法或建议我的情况有什么不对?
非常感谢您的时间和帮助。
感谢您发表评论@DanielMaclean,我想没有那些线,但结果相同。另一方面,我的服务器现在允许两个连接。 – santiPipes
你可以尝试禁用服务器上的1.1吗? – LewisT
我不能,服务器必须允许这两个连接。我实际上使用TLS1.1和TLS1.2连接付款终端到这台服务器,没有麻烦。 – santiPipes