httpclient PostAysnc 方法有时会抛出 Javax.Net.Ssl.SSLException。我确信端点 url 和 httpContent 是有效的。这种异常只发生在非常低的频率。
异常消息是“读取错误:ssl=0x716ae3b788:发生 SSL_ERROR_WANT_READ。您永远不会看到这个。”
项目环境:Xamarin.Android with NETStandard.Library 2.0.3 Android 构建配置:HttpClient 实现:“AndroidClientHandler” SSL/TLS 实现:“Native 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();
}
}