1

Making a get request to an HTTP REST API from an Ionic and Angular app. When making the request on a home network the API receives and responds correctly to every request.

However, when I make the same request on a 4g data connection only the first request is successful. In all following requests, the server never receives said request, but the $http.get acts as though it receives a response and reports a status code of 200. In these cases the "response" never changes from the response the initial request resulted in.

Clearing the app data restarts this cycle: the first request after the clear succeeds, and that response is repeated.

This is the function which makes the GET request. The contents of res are shown in the screenshot below.

 this.getSongInfo = function() {
    return $http.get('http://REDACTED:8080/getName').then(function(res) {
      console.log(res);
      return res.data;
    }, function(err) {
      console.log(err);
      return false;
    });
  }

A screenshot of the response from the $http.get function. The response is the same as the first request each time after

UPDATE Lex's answer helped. I had not realised I couldn't inject $httpProvider into a service. Once I added it as to my app.config everything seemed to work correctly. Still not sure why it was only caching when on a data connection though, I couldn't find anything in the angular documentation to say that caching is enabled for data connections.

  • Does disabling the caching as described in [this answer](http://stackoverflow.com/a/19771501/548997) have any effect? – Lex Mar 17 '16 at 15:38
  • Thank you, that has done the trick. I tried to use this solution earlier but I failed to realise I couldn't use $httpProvider in services. Now that I've put it in my app.config seems to work as expected. –  Mar 17 '16 at 15:53
  • @Lex, you should make your comment an answer – Ladmerc Mar 18 '16 at 09:02

1 Answers1

0

It sounds like the response is being cached somewhere. This is useful when you expect the same request to return the same response every time, but your case, that's obviously not the desired behavior. Based on what you've provided there is no way to know what external tool/setting is causing the response to be cached.

Austin
  • 1,291
  • 10
  • 19