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;
});
}
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.