5

I am using Visual Studio 2013 Update 4 and I have a web api project setup to receive get requests that returns an array. For the client app I have setup cordova and am emulating an android angular app using ng-resource to call the web api get. Everytime I call the GET I get a ripple.js error that says connection refused. I get the connection refused even if I try with a real android device as well. 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 to enable cors on the web api 2 server since the cordova and web api projects are different port numbers on the same local host. I proved not only the cors functionality but also the code by creating an exact replica of the cordova angular app with just angular web page. I also tried with postman and both get json responses correctly. It is only the cordova android app that is giving me the connection refused. Any help would be greatly appreciated!

Here is what the angular get looks like

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

This shows I am allowing all domains on the web api project:

 <httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
  </customHeaders>
</httpProtocol>
2
  • have you whitelisted the api domain in your cordova config.xml. see cordova.apache.org/docs/en/edge/…
    – Amitesh
    Commented Nov 25, 2014 at 5:28
  • There was an asterisk there so I assume all were white listed. I also just explicitly added the web api localhost but no luck. Any other suggestions?
    – Sealer_05
    Commented Nov 25, 2014 at 5:36

2 Answers 2

12

The solution was to disable cross domain proxies from the drop down right in the emulator. Easy mistake to make if you aren't familiar with the ripple emulator.

4
  • Do you have other suggestions? I've added all domains in both webapi project and in cordova config, disabled the ripple proxy, still no luck. (It works in azure, just localhost is the trouble)
    – Larsi
    Commented Jan 31, 2015 at 16:47
  • Have you tried all three settings in ripple? Remote, local, and disabled I believe. Also maybe you are having a cors issue?
    – Sealer_05
    Commented Feb 2, 2015 at 20:31
  • 1
    @Larsi It's been many months, but I hope you've found a solution to your issue. If not, see my answer below about using Android special address 10.0.2.2
    – Erin Geyer
    Commented Jul 9, 2015 at 20:49
  • @ErinGeyer - thanks for commenting. Yes I found a sln, but unsure what it was - I should have updated my comments, sorry for that.
    – Larsi
    Commented Jul 10, 2015 at 19:50
6

The answer as it pertains to issues with accessing http://localhost (which is the same thing as 127.0.0.1) can be found here: http://developer.android.com/tools/devices/emulator.html - which says:

"Also note that the address 127.0.0.1 on your development machine corresponds to the emulator's own loopback interface. If you want to access services running on your development machine's loopback interface (a.k.a. 127.0.0.1 on your machine), you should use the special address 10.0.2.2 instead."

So, instead of using http://localhost use http://10.0.2.2 and then append whatever port you're using. Example: http://localhost:8001 can be access at http://10.0.2.2:8001

Not the answer you're looking for? Browse other questions tagged or ask your own question.