Xamarin.Forms Android App无法连接到互联网

时间:2018-04-09 23:12:31

标签: android xamarin.forms xamarin.android

我有一个锅炉板Xamarin.Forms跨平台应用程序。我不知道允许ANDROID App连接到互联网的设置是什么。在UWP中,我必须启用一些功能,现在它可以工作。在Android Manifest我启用了“互联网”,但仍然没有运气不确定是什么遗漏。

      public MainPage()
    {

        InitializeComponent();

        HttpClient client = new HttpClient();
        CurrentRaceInfo cur_race = new CurrentRaceInfo();
        try
        {
            var cur_racedetail = await client.GetStringAsync("Place URL here");

        }
        catch (Exception e)
        {
            var ooo = e;
            throw;
        }
    }
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: ConnectFailure (Connection timed out) ---> System.Net.Sockets.SocketException: Connection timed out
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000b6] in :0 
  at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0016d] in :0 
   --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00058] in :0 
  at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in :0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0 
  at System.Net.Http.HttpClientHandler+d__63.MoveNext () [0x00450] in :0 
   --- End of inner exception stack trace ---
  at System.Net.Http.HttpClientHandler+d__63.MoveNext () [0x004ab] in :0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0 
  at System.Net.Http.HttpClient+d__49.MoveNext () [0x000ca] in :0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in :0 
  at System.Net.Http.HttpClient+d__54.MoveNext () [0x0007d] in :0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in :0 
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in :0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in :0 
   --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0004b] in :0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0 
  at NInterpret.Interpreter.callAMethod (NInterpret.AMethod m, NInterpret.AType[] ptypes, NInterpret.AType[] genericMethodArgs, System.Collections.Generic.Dictionary`2[TKey,TValue] genericArgsIndex, System.Object[] args, System.Collections.Generic.List`1[T] byRefArgs, Microsoft.FSharp.Core.FSharpOption`1[T] byRefTarget, System.Object target, System.Boolean virtualCall) [0x0049b] in :0 
  at NInterpret.Interpreter.callMethodReference (System.Collections.Generic.Dictionary`2[TKey,TValue] gargs, Mono.Cecil.MethodReference ms, System.Boolean virtualCall) [0x00384] in :0 
  at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet`1[T] inTries, Microsoft.FSharp.Core.FSharpOption`1[T] lastException) [0x00fb7] in :0 
  at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet`1[T] inTries, Microsoft.FSharp.Core.FSharpOption`1[T] lastException) [0x0013c] in :0 } 

我可以通过创建使用VS 2017文件>创建错误;新项目>网络>跨平台>移动应用程序(Xamarin.Forms)>我选择空白项目,在IOS,ANdroid和UWP中放置复选框。选择.Net Standard作为代码共享策略。按确定。设置prject之后我将Android设置为启动项目,将上面的代码放在共享项目MainPage.Xaml.cs中对于模拟器我使用Xamarin Live播放器连接到我的手机它的Android API 24.我设置了一些断点和运行项目。然后它会在Client.GetStringAsync()调用上抛出以下错误。如前所述,我对UWP有类似的问题,但我所要做的就是启用一些功能并且问题消失了,我相信我会在IOS上遇到类似的问题,但现在只处理1个问题。

0 个答案:

没有答案