Xamarin表单 - 在await client.PostAsync()

时间:2017-08-18 08:51:43

标签: xamarin xamarin.forms

非常奇怪的问题(所有代码都在PCL中)。

当我针对网络服务(API')致电await client.PostAsync()时,我会收到TaskCanceledException

很少有事情需要注意:

这在Android设备上正常运行。它只发生在我在iOS上运行应用程序时,但是......

...让它更奇怪,如果我使用承载我{{1}查询的API的不同(物理)服务器,可以让它在iOS上运行}。

所以,

更奇怪的是,两台服务器运行完全相同的webservice ,有0差异,唯一的区别是服务器位于不同客户端的不同站点上。因此,故障不在于查询的Web服务抛出超时或取消请求。

两台服务器都拥有有效(可信)的SSL证书,因此它不是SSL相关问题。

我被困住了。我已尝试await client.PostAsync()并增加ModernHttpClient

我还检查了client.TimeSpan,这是假的,所以假设它是"超时"的时间是非常安全的。但是,当我从PostMan手动对该API运行Post请求时,很明显web服务正常工作(没有超时)。

ex.CancellationToken.IsCancellationRequested

异常详情:

  

{System.Threading.Tasks.TaskCanceledException:任务被取消   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess   (System.Threading.Tasks.Task任务)[0x0002d] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179   在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification   (System.Threading.Tasks.Task任务)[0x0002e] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156   在System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd   (System.Threading.Tasks.Task任务)[0x0000b] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128   在System.Runtime.CompilerServices.TaskAwaiter`1 [TResult] .GetResult()   [0x00000] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357   在System.Net.Http.HttpClientHandler + c__async0.MoveNext()   [0x004c1] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs:391

     

---抛出异常的前一个位置的堆栈跟踪结束--- at   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()   [0x0000c] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess   (System.Threading.Tasks.Task任务)[0x00027] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176   在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification   (System.Threading.Tasks.Task任务)[0x0002e] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156   在System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd   (System.Threading.Tasks.Task任务)[0x0000b] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128   在   System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1 + ConfiguredTaskAwaiter [TResult] .GetResult   ()[0x00000] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535   在System.Net.Http.HttpClient + c__async0.MoveNext()   [0x000a9] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:276

     

---抛出异常的前一个位置的堆栈跟踪结束--- at   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()   [0x0000c] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess   (System.Threading.Tasks.Task任务)[0x00027] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:176   在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification   (System.Threading.Tasks.Task任务)[0x0002e] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156   在System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd   (System.Threading.Tasks.Task任务)[0x0000b] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128   在System.Runtime.CompilerServices.TaskAwaiter`1 [TResult] .GetResult()   [0x00000] in   /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.128/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357   在XamarinMO.Services.TokenService + d__4.MoveNext()   C:\ Users \ johns \ OneDrive \ Sources \ WinMan API和Xamain中的[0x000e3]   App \ XamarinMO \ XamarinMO \ XamarinMO \ Services \ TokenService.cs:67}

1 个答案:

答案 0 :(得分:0)

经过许多个小时,我找到了解决方案:

可以通过将项目属性下的TLS设置更改为Mono而不是Apple来修复。这是由于iOS上的SSL / TLS新Apple TLS默认设置中的错误。