0

I have set up Flurl to run within my Xamarin PCL, and I'm calling off to a Web Api I have running in an MVC application.

It seems Flurl can hit my deployed API no problem, but I'm unable to test changes locally for some reason.

Here's what I'm doing:

var data = await "http://localhost:60257/api/gigapi".GetJsonAsync<List<Gig>>();

I've tried a simple GetAsync() too but again, no avail.

Any help would be appreciated.

EDIT:

Just for a bit more info, the project is a redevelopment of an Ionic mobile app. I've run the ionic app locally and that's able to hit my local web api with no issues, so it's not a firewall issue or anything like that - It's probably something I'm doing wrong in Flurl.

EDIT2:

Here's the Exception:

e.Message "Request to http://localhost:60257/api/gigapi failed. Error: ConnectFailure (Connection refused)" string

And the stacktrace:

StackTrace " at Flurl.Http.Configuration.FlurlMessageHandler+d__1.MoveNext () [0x003ec] in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:62 \n--- End of stack trace from previous location where exception was thrown ---\n at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00042] in <1c7d529d87ec4bdcbde02e9494f3b5ae>:0 \n at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess (System.Threading.Tasks.Task task) [0x0001c] in <1c7d529d87ec4bdcbde02e9494f3b5ae>:0 \n at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00009] in <1c7d529d87ec4bdcbde02e9494f3b5ae>:0 \n at Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <1c7d529d87ec4bdcbde02e9494f3b5ae>:0 \n at Flurl.Http.HttpResponseMessageExtensions+<ReceiveJson>d__01[T].MoveNext () [0x00024] in C:\projects\flurl\src\Flurl.Http.Shared\HttpResponseMessageExtensions.cs:26 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 \n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 \n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 \n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 \n at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 \n at SarifForms.Login+d__1.MoveNext () [0x00033] in C:\Users\Minneth\Documents\Projects\SarifForms\SarifForms\Login.xaml.cs:31 " string

FINAL UPDATE:

Answer posted below.

Martin Crawley
  • 477
  • 1
  • 7
  • 16

1 Answers1

0

Bit obvious reallly, but I think I've worked out the issue.

I'm testing my Xamarin app that's using Flurl from the Android Emulator, so localhost is actually the Android Emulator - Not my local web api running on the same machine.

I believe I have to use the loopback IP of 10.0.2.2 instead.

The reason it works with my Ionic app is because I'm running the Ionic app in the browser rather than the Andorid emulator.

Hope this helps someone.

Martin Crawley
  • 477
  • 1
  • 7
  • 16