httpclient PostAysnc方法有时会引发Javax.Net.Ssl.SSLException。 我确定端点url和httpContent有效。这种异常仅在非常低的频率下发生。
异常消息为“读取错误:ssl = 0x716ae3b788:发生SSL_ERROR_WANT_READ。您永远都不会看到此消息。”
项目环境:带有NETStandard.Library 2.0.3的Xamarin.Android Android构建配置: HttpClient实现:“ AndroidClientHandler” SSL / TLS实施:“本地TLS 1.2 +”
下面是详细信息堆栈跟踪:
Java.Interop
JniEnvironment+InstanceMethods.CallIntMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args)
Java.Interop
JniPeerMembers+JniInstanceMethods.InvokeVirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
Java.Net
HttpURLConnection.get_ResponseCode ()
Xamarin.Android.Net
AndroidClientHandler+<>c__DisplayClass46_0.<DoProcessRequest>b__1 ()
System.Threading.Tasks
Task`1[TResult].InnerInvoke ()
System.Threading.Tasks
Task.Execute ()
Xamarin.Android.Net
AndroidClientHandler.DoProcessRequest (System.Net.Http.HttpRequestMessage request, Java.Net.URL javaUrl, Java.Net.HttpURLConnection httpConnection, System.Threading.CancellationToken cancellationToken, Xamarin.Android.Net.AndroidClientHandler+RequestRedirectionState redirectState)
Xamarin.Android.Net
AndroidClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
System.Net.Http
HttpClient.SendAsyncWorker (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken)
UbiParkLib.Services.ApiCommon
APIBaseService.Post (System.String endPoint, System.Object payload) /Users/kevinhu/Source/UbiParkApp/UbiParkApp/UbiParkLib/Services/ApiCommon/APIBaseService.cs:371
源代码: “ await _httpClient.PostAsync(endPoint,httpContent)”是引发异常的行。
using (HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json"))
{
using (var response = await _httpClient.PostAsync(endPoint, httpContent))
{
response.EnsureSuccessStatusCode();
result = await response.Content.ReadAsStringAsync();
}
}
答案 0 :(得分:0)
我想我已经找到了导致此异常的原因和解决方案。原因是Android AndroidClientHandler在处理HTTP请求期间会抛出Java异常。 (但是,iOS处理程序将抛出.NET HttpRequestException或WebException)。这些异常通常在网络不稳定时发生,如果我们再试一次就可以了。对于我的情况,因为我应用了Polly策略,所以我只是捕获了所有异常,并通过字符串比较来确定异常类型的名称。有关android处理程序的参考:github.com/xamarin/xamarin-android/issues/3216