0

So I've got a basic custom GET in angular using $resource

angular.module('myApp')
  .factory('MyService', function($resource){
    return $resrouce('some url',
    {},
    {
       list: {method:'GET', params:{}}
    });
  });

I then use it like this

MyService.list().$promise.then(function(data){
   //do something
});

When I use it in Chrome (33) it works. In firefox (10.0.2) however I get a

401 unauthorized

If I go to the url directly within firefox I get the data.

The service and my page are hosted on different boxes. I wondered if it's got something to do with cross site protection or something? Any thoughts?

EDIT: I've tried enabling CORS as per this answer but again no help.

EDIT2: the 401 response has no body. The headers are pretty basic...

HTTP/1.1: 401 Unauthorized
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 UTC
Content-Length: 1174
Date: Tue, 14 Jul 2015 08:52:16 GMT
Community
  • 1
  • 1
Captastic
  • 1,036
  • 3
  • 10
  • 19
  • 1
    There doesn't seem to be anything wrong with your code, maybe Chrome has an Auth cookie that Firefox doesn't have? Does the request give a response in the network tab? – Pepijn Jul 14 '15 at 08:43
  • Thanks for the reply. I get no response body but I do get a basic response header. I'll update the question. – Captastic Jul 14 '15 at 09:00

1 Answers1

0

Problem solved. I needed to add

$httpProvider.defaults.withCredentials = true;

Looks like it was a CORS error

Captastic
  • 1,036
  • 3
  • 10
  • 19