Cannot make HTTP GET request from Windows 10 (UWP) app - returns code 500


#1

Hi there! I’m building a small app, which needs to synchronise with an Express (NodeJS) server on my Raspberry Pi. So far that consists of uploading or downloading a JSON object to/from the server which is on my local network. I want to deploy the app on both Android and Windows 10, but I’m having big issues with the latter.

I understand CORS is an obstacle to external connections, so I’ve setup a proxy in my ionic.project file. The proxy routes “/pi” to “http://raspberrypi:3535/”.

I’ve also added cordova-plugin-whitelist to the project and the following lines of code:
In config.xml - <allow-navigation href="http://*/*" />
In index.html - <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

I have a service with the following download function:

this.download = function() {
  return $http.get(url)
    .success(function(data, status, headers, config) {
      $ionicPopup.alert({
        title: 'HTTP GET Succeeded',
        template: JSON.stringify(status)
      });
      $ionicPopup.alert({
        title: 'HTTP GET Succeess status',
        template: JSON.stringify(data)
      });
    })
    .error(function(data, status, headers, config) {
      $ionicPopup.alert({
        title: 'HTTP GET Error status',
        template: JSON.stringify(status)
      });
      $ionicPopup.alert({
        title: 'HTTP GET Error status',
        template: JSON.stringify(data)
      });
    });
};

The variable url is declared higher up and has a default value of “/pi”, which only changes to “http://raspberrypi:3535/”, when running on Android.

Note that I’m using alerts because “ionic run windows -l -c” doesn’t work - the app freezes on startup.

So far I’ve confirmed that the function works perfectly in serve mode on Chrome/Edge, and as an app on Android. But when I deploy it on Windows 10 (as UWP app), It returns a status 500 error, and data and config are empty or undefined (I couldn’t see through the alerts).

I’ve tried using XMLHttpRequest instead and I get the exact same results, only Windows 10 doesn’t work. I’ve also tried using the full address “http://raspberrypi:3535” for the HTTP GET request, but then I get a code 0, presumably because CORS is blocking it.

I’m completely stumped and I don’t see why it doesn’t work, given that all other platforms have no issues. Another (possibly unrelated) thing that confuses me is that both Windows 10 UWP apps and the Edge browser return ‘true’ when invoking ionic.Platform.isEdge(), so presumably they use a similar platform.

If anyone can think of any solution to this, I’d be eternally grateful! I’ve been scouring the internet for solutions all day and none of them have worked.

Thank you in advance!


#2

Hi,

I am getting the same problem. Did you get to resolve it ? If yes, you could tell me how.

Thanks,

Leo.


#3

Hi all, i have exaclty the same problem. Cors are well managed in my app and i have no problem with android and browser but when i run the app inside windows 10 i have “Response with status: 0 for URL: null”. I also try with a proxy without success. Do you have find any solutions ?


#4

I have the same problem, have you fixed it?


#5

Yes you have to unlock the windows app using something like Fiddler.

Install fidler from telerik : https://www.telerik.com/download/fiddler
Once open click on “WinConfig”, a new screen open named “AppContainer Loopback Exemption Utility”, find and check your app then click on save.

After that it working for me.


#6

So you found no way of doing this from the source code?