Cordoba Angular Get Web Api Connection Denied

I am using Visual Studio 2013 Update 4, and I have set up an api web project to receive receive requests that return an array. For a client application, I have a cordova setup and emulation of an android angular application using an ng resource to call the web api get. Every time I call GET, I get a ripple.js message stating that the connection is rejected. I get a connection failure even if I try with a real Android device. Here is the error when using the ripple emulator

OPTIONS http://****:4400/ripple/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rur…Fget%3D%257B%2522method%2522%3A%2522GET%2522%2C%2522array%2522%3Atrue%257D net::ERR_CONNECTION_REFUSED

I was sure that I enabled cors on the api 2 web server, since the cordova and web api projects are different port numbers on the same local host. I proved not only the functionality of cors, but also the code by creating an exact copy of the cordova angular application with only the angular web page. I also tried with the postman, and both answered json correctly. This is only android cordova app which gives me connection rejection. Any help would be greatly appreciated!

Here is what angular looks like:

 app.factory('mrMaintService', function ($resource) { return $resource('http://localhost:15528/api/requests', { get: { method: 'GET', array: true } }); }); 

This shows that I resolve all domains in the web api project:

  <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> 
+5
source share
2 answers

The solution was to disable cross-domain proxies from the drop-down on the right in the emulator. A slight mistake if you are not familiar with the ripple emulator.

+13
source

The answer to the question related to access to http://localhost (the same as 127.0.0.1 ) can be found here: http://developer.android.com/tools/devices/emulator.html - which reads:

"Also note that the address 127.0.0.1 on your development machine corresponds to the native loopback interface for the emulator. If you want to access the services running on your development loopback interface (aka 127.0.0.1 on your computer), you should use instead instead, you should specify the special address 10.0.2.2.

So, instead of using http://localhost use http://10.0.2.2 , and then add any port you use. Example: http://localhost:8001 may be access to http://10.0.2.2:8001

+5
source

Source: https://habr.com/ru/post/1207637/


All Articles