xamarin.forms httpclient lte太慢了

时间:2017-11-13 16:10:37

标签: android xamarin.forms httpclient

在我的Crossplatform应用程序中,我使用httpClient和NativeMessageHandler。 我通过httpclient调用web服务。当我通过WLAN打电话给网络服务时,它可以完美地工作,没有WLAN,因此iPhone上的LTE也能完美运行。但是如果我在Android上激活LTE,如果我没有设置超时值,我会在下一行中获得超时。但如果我设置Timeout,那么Post Post需要超过几分钟:

client = new HttpClient(new NativeMessageHandler());
client.BaseAddress = new Uri(App.hostserveradress);
client.Timeout = TimeSpan.FromMinutes(20);
var contentReset = new StringContent(mobileJSON, Encoding.UTF8, "application/json");
var responseReset = await client.PostAsync("GetResetFotos", contentReset); **// ERROR**
var resultReset = await responseReset.Content.ReadAsStringAsync();

更新

Try Catch块出错:

System.OperationCanceledException: The operation was canceled.
  at ModernHttpClient.NativeMessageHandler+<SendAsync>c__async0.MoveNext () [0x00422] in <51795dd1dbb344bdacae7208f448a6b3>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
  at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x000ca] in <7736395a6c71409691a34accfc621095>:0 

如果我添加了Timeout,Post会恢复数据,但这对LTE来说太慢了。 接收数据需要几分钟。 这是我从PostAsync回来的内容:

{StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: ModernHttpClient.ProgressStreamContent, Headers:
{
Cache-Control: max-age=0, private
Date: 16.11.2017 10:34:35 +00:00
OkHttp-Received-Millis: 1510828472777
OkHttp-Selected-Protocol: http/1.1
OkHttp-Sent-Millis: 1510828472613
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 330
Content-Type: application/json; charset=utf-8
OkHttp-Received-Millis: 1510828472777
OkHttp-Selected-Protocol: http/1.1
OkHttp-Sent-Millis: 1510828472613
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
}}

我的错误是什么?

0 个答案:

没有答案