我已经将Flurl设置为在我的Xamarin PCL中运行,并且我正在调用我在MVC应用程序中运行的Web Api。
似乎Flurl可以点击我部署的API没问题,但由于某种原因我无法在本地测试更改。
这就是我正在做的事情:
var data = await "http://localhost:60257/api/gigapi".GetJsonAsync<List<Gig>>();
我已经尝试了一个简单的GetAsync(),但是再次无效。
任何帮助都将不胜感激。
编辑:
仅为了解更多信息,该项目是Ionic移动应用程序的重新开发。我已在本地运行离子应用程序,并且能够毫无问题地点击我的本地网络API,因此它不是防火墙问题或类似的东西 - 它可能是我和我的关系#39;我在Flurl做错了。
EDIT2:
这是例外:
e.Message&#34;对http://localhost:60257/api/gigapi的请求失败。错误:ConnectFailure(拒绝连接)&#34;串
堆栈跟踪:
StackTrace&#34; at Flurl.Http.Configuration.FlurlMessageHandler + d _1.1.MoveNext()[0x003ec]在C:\ projects \ flurl \ src \ Flurl.Http.Shared \ Configuration \ FlurlMessageHandler.cs:62 \ n ---堆栈跟踪结束抛出异常的先前位置--- \ n在Microsoft.Runtime.CompilerServices的&lt; 1c7d529d87ec4bdcbde02e9494f3b5ae&gt;中的Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x00042]中:\ n在&lt; 1c7d529d87ec4bdcbde02e9494f3b5ae&gt;中的TaskAwaiter.HandleNonSuccess(System.Threading.Tasks.Task任务)[0x0001c]:在&lt; 1中的Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task任务)[0x00009]中的0 \ n ; 1c7d529d87ec4bdcbde02e9494f3b5ae&gt;:0 \ n at Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable 1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <1c7d529d87ec4bdcbde02e9494f3b5ae>:0 \n at Flurl.Http.HttpResponseMessageExtensions+<ReceiveJson>d__0
1 [T] .MoveNext()[0x00024]在C:\ projects \ flurl \ src \ Flurl.Http.Shared \ HttpResponseMessageExtensions.cs :26 \ n ---从抛出异常的上一个位置开始的堆栈跟踪结束--- \ n在System.Runtime.Excep中/Seriners/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 \ n at中的tionServices.ExceptionDispatchInfo.Throw()[0x0000c] / Users / builder / data / lanes / 3819 / 96c7ba6c / source / mono / mcs / class / referencesource / mscorlib / system /中的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x00047] runtime / builder / data / lanes / 3819 / 96c7ba6c / source /中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task任务)[0x0002e]中的runtime / compilerservices / TaskAwaiter.cs:187 \ n / Users / ms / class / referencesource / mscorlib / system / runtime / compilerservices / TaskAwaiter.cs:156 \ n在/ Users /中的System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task任务)[0x0000b] builder / data / lanes / 3819 / 96c7ba6c / source / mono / mcs / class / referencesource / mscorlib / system / runtime / compilerservices / TaskAwaiter.cs:128 \ n at Sys tem.Runtime.CompilerServices.TaskAwaiter`1 [TResult] .GetResult()[0x00000]在/ Users / builder / data / lanes / 3819 / 96c7ba6c / source / mono / mcs / class / referencesource / mscorlib / system / runtime / compilerservices中/TaskAwaiter.cs:357 \ n在SarifForms.Login + d__1.MoveNext()[0x00033]在C:\ Users \ Minneth \ Documents \ Projects \ SarifForms \ SarifForms \ Login.xaml.cs:31&#34;串
最终更新:
下面发布的答案。
答案 0 :(得分:0)
显然有点明显,但我认为我已经解决了这个问题。
我正在使用Android模拟器中的Flurl测试我的Xamarin应用,因此localhost实际上是Android模拟器 - 而不是我在同一台计算机上运行的本地网络API。
我相信我必须使用10.0.2.2的环回IP。
它与我的Ionic应用程序一起使用的原因是因为我在浏览器而不是Andorid模拟器中运行Ionic应用程序。
希望这有助于某人。