CORS is normally a server side issue. The server must authorize the client to access it. But provided that you say it works in the browser, it probably has CORS implemented. You can check by using a program like Postman to send a request, and see if the following occurs.
The browser sends (Or you can manually send via Postman) a request before your request called a preflight request. This is to make sure that the server supports the HTTP method that you are about to call. The preflight request will contain the origin header:
Origin: http://foo.example
And assuming that the server has implemented CORS, it will come back with this in the header:
Access-Control-Allow-Origin: *
If the above line is present, you should not have an issue. So, in the angular app, you should include the first code snippet, and the server should return the second snippet. If you do have access to the backend, go make sure that the second snippet is inserted in the response.
The preflight request and response exchange should look something like what follows (view full post).
I also learned a lot from this article
Preflight Request:
OPTIONS /resource/foo
Access-Control-Request-Method: DELETE
Access-Control-Request-Headers: origin, x-requested-with
Origin: https://foo.bar.org
Response:
HTTP/1.1 200 OK
Content-Length: 0
Connection: keep-alive
Access-Control-Allow-Origin: https://foo.bar.org
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
Access-Control-Max-Age: 86400
So in your app, you need to include the Origin : http://your.domain
kind of like the following request and response:
GET /resources/public-data/ HTTP/1.1
Host: bar.other
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Referer: http://foo.example/examples/access-control/simpleXSInvocation.html
Origin: http://foo.example
HTTP/1.1 200 OK
Date: Mon, 01 Dec 2008 00:23:53 GMT
Server: Apache/2.0.61
Access-Control-Allow-Origin: *
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/xml
[XML Data]