Angular $ http.get to localhost, always returns 404. 200 in the browser

I cannot create a successful receive request in Angular 1.2.13.

  var getProgress = function() {
      var promise = $http({method: 'GET', url: 'http://localhost:8080/project/local/some/getStatus'});

      promise.then(function(success) {
        alert(JSON.stringify(success));
      }, function(error) {
        alert(JSON.stringify(error));
      }, function(notify) {
        alert(JSON.stringify(notify));
      });
  };    

So, I'm trying to get JSON from my REST web service. To check the service, I access it from browsers (IE9, Firefox 27, Chrome 33) works fine in all of them.

The above code using Angular always causes an error:

* {"data": "," status ": 404," configuration ": {" transformRequest ": [empty]" transformResponse ": [zero]," method ":" GET "," URL ": "http://localhost:8080/project/local/some/getStatus"," headers " : {"Accept": "application / json, text / plain, /"}}} ​​*

wireshark HTTP- HTTP-, - , Angular 200, json!! Angular 404.

Firefox Angular Findbugs, HTTP- 200, Angular 404. Angular , .

IE9!

.

+4
4

@GeoffGenz && @BKM . CORS . , .

@Provider
public class RespFilter implements ContainerResponseFilter {
    @Override
    public void filter(ContainerRequestContext reqContext, ContainerResponseContext respContext) throws IOException {
        respContext.getHeaders().putSingle("Access-Control-Allow-Origin", "*");
    }
}
+3

. , EnableCors, CORS WebAPI.

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.EnableCors();            
        ....
    }
}
0

IE, IE :\ html. , :\\ http-, .

0

:

$http({method: 'GET', url: 'http://localhost:8080/project/local/some/getStatus'}).
    success(function(data, status, headers, config) {
       alert(JSON.stringify(data));
    }).
    error(function(data, status, headers, config) {
      alert(JSON.stringify(data));
    });
-2

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


All Articles