Xamarin Android:Https发布请求到本地Intranet Web Api导致错误:StatusCode:404,ReasonPhrase:' Not Found'

时间:2017-09-21 03:38:14

标签: xamarin encryption xamarin.forms xamarin.android tls1.2

这将是一个很长的问题..

我们公司必须遵循PCI Standards,所以不久前我们必须确保所有服务器都符合TLS1.2标准。因此,我们在Xamarin Forms应用程序中按照here解释实现了TLS。但我们注意到Android版本中的问题少于Api 22.所以我们实现了一个依赖服务来获取HTTPClient,如果Api版本小于22,我们实现了一个自定义ssl套接字工厂,here's示例。

一切都很好,直到几个星期前,我们决定在开发环境中将服务器升级到Windows 2016。我们已将Web Api重新部署到服务器,从那时起,api无法从少数设备访问。我们遇到的问题是三星Galaxy S4(Android 4.4)和Nexus 5(Android 5.1.1)。我们尝试在三星Galaxy A7(Android 6)上测试应用程序,它运行正常。 iOS也没关系。 这是我们在S4和Nexus 5上收到的错误

  

StatusCode:404,ReasonPhrase:' Not Found',版本:1.1,内容:   System.Net.Http.StreamContent,Headers:{Date:Wed,2017年9月20日   04:00:09 GMT服务器:Microsoft-IIS / 10.0 X-Android-Received-Millis:   1505880010792 X-Android-Response-Source:NETWORK 404   X-Android-Selected-Transport:http / 1.1 X-Android-Sent-Millis:   1505880010781 X-Powered-By:ASP.NET内容长度:1245内容类型:   text / html的

这里是Web Api的签名

[HttpPost("GetMinimumVersion")]
public GetMinimumVersionResponse GetMinimumVersion([FromBody] GetMinimumVersionRequest value)

这是我们用来发布帖子请求的代码

using (_httpclient = _deviceInfo.GetHttpClient())
                {
                    _httpclient.MaxResponseContentBufferSize = 256000;
                    _httpclient.BaseAddress = new Uri(BaseAddress);
                    _httpclient.Timeout = timeout > 0 ? TimeSpan.FromSeconds(timeout) : TimeSpan.FromSeconds(60000);
                    Insights.Track("ApiUrlCalled", new Dictionary<string, string> { { "Api URL", url } });
                    var jsonOut = new StringContent(JsonConvert.SerializeObject(body, new IsoDateTimeConverter()));
                    jsonOut.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    HttpResponseMessage response = await _httpclient.PostAsync(url, jsonOut);
                    switch (response.StatusCode)
                    {
                        case HttpStatusCode.OK:
                            var content = await response.Content.ReadAsStringAsync();
                            var result = JsonConvert.DeserializeObject<T>(content);
                            ReceiveNotificationDateTime(result);
                            return result;
                        default:
                            var result1 = new T { StatusID = (int)SystemStatusOutcomes.Failed, StatusMessage = response.ToString() };
                            ReceiveNotificationDateTime(result1);
                            return result1;
                    }
                }

值得注意的是,在与生产API通信时,应用程序可以在所有设备上正常工作。我们还可以通过Postman向dev api发布帖子请求。

经过一番挖掘和刮擦后,我发现生产和开发时使用的密码不同。

这是Prod Production Cipher上使用的密码 这是dev Dev Cipher上使用的那个。

我查看了SSL Ciphers Android支持here。看起来Android Api版本20+支持ciper套件TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384。这有意义,它不适用于Android 4.4。但是为什么我们会在Nexus 5上出现这个错误?有什么指针吗?

还有什么解决方法可以在Android 4.4上启用此密码吗?

0 个答案:

没有答案
相关问题