0

I'm building an application with Xamarin.Forms and a Portable Class Library. I try to do an API call which returns JSON. I have problems when running the project on Universal Windows Platform. This is the code that throws an error:

using (HttpClient wc = new HttpClient())
{
   var data = await wc.GetStringAsync("http://something.e1923.companyname.local/content-api/Category/?format=json");

This is the error:

Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.ni.dll at System.Net.Http.HttpClientHandler.d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Somethoing.RESTConnection.d__4.MoveNext()

When I used the same code but an other URL it worked perfect:

wc.GetStringAsync("http://something.localhost.companyname.local/content-api/Category/?format=json");

The code does work on Android, but not in Universal Windows Platform. Why is the above code (without localhost) not working on UWP?

I only changed from localhost to an other URL. The only requirement to have access to the non-localhost URL (in my particular case) is that you are connected to the right network (same as where the website is hosted).

476rick
  • 2,764
  • 4
  • 29
  • 49
  • 1
    Did you check this post? http://stackoverflow.com/a/39317424/361100 Anyway, blocking Non-loopback is weird. Blocking loopback is understandable. – Youngjae Oct 18 '16 at 12:41
  • Did you add the required capabilities to your UWP app? (https://msdn.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations) – Krumelur Oct 18 '16 at 13:50
  • @Krumelur, yes, I have checked the capabalities: Internet (Client) and Internet (Client & Server) – 476rick Oct 19 '16 at 09:13
  • @Youngjae I read the post and its links, but I still cannot fix the problem.. – 476rick Oct 19 '16 at 14:24

1 Answers1

1

Krumeler asked me in the comments if I did add the required capabilities in my UWP app, so I wen't looking.

The one I didn't check was: Private Networks (Client & Server).

This was the one that needed to be checked. It works now, thanks!

476rick
  • 2,764
  • 4
  • 29
  • 49