Search code examples
javascriptxmlhttprequestwindows-store-appswinjsjqxhr

Windows Store App xhr to localhost fails


I have a Win Store App app which uses REST to communicate with a pinpad device attached by USB. It has it's own proprietary http server/software but it seems fairly simple.

In my dev machine and on my test machine all works as expected. However, on my tester's machine it does not. The issue is that the xhr GET is failing. It just times out and returns status 0.

A simple get using a browser is successful, as is a script run in a browser (ie, ff, ch).

I have swapped out xhr for httpClient, jquery.ajax and a direct XMLhttpRequest call - all have the same result. I have tried setting location header for CORS. Tried different formats for the address (localhost, 127.0.0.1, 192... etc). The app will happily get external content (eg google.com).

Has anyone come across something like this before? I suspect it's something to do with how a Windows Store App interacts with the lan but I don't know where else to look.


Solution

  • By default Windows Store apps are blocked from loopback connections to localhost. By default, Visual Studio sets up an exception when debugging and you can set one up yourself for testing or for side-loaded apps with the checknetisolation tool. If your app will be deployed from the store it cannot rely on a loopback exemption.

    See Using network loopback in side-loaded Windows Store apps on MSDN:

    To add a Windows Store app to the list of apps that are exempt from the loopback firewall, run checknetisolation loopbackexempt -a -n=<package family name> from an elevated command prompt. The package family name for a Windows Store app is available from Visual Studio via the Package.appxmanifest editor on the packaging tab.