1

I try to send a GET RESTful request to a server with basic authentication. I wrote the following code to achive this task:

module.controller("MainCtrl", ['$scope', '$http', function($scope, $http) {
            $http.get('http://192.168.10.15:8080/web/services/api/records/20420?_type=json', {
                headers:  {
                    'Authorization' : 'Basic username:password'}
            })
            .success(function(response) {
                console.log("my success");
                $scope.values = response;
              })

            }]
        );

When the request is processed, the given error is displayed on the browser console:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource on http://192.168.10.15:8080/web/services/api/records/20420?_type=json. (Reason: header CORS 'Access-Control-Allow-Origin' missing).

Any Idea?

3 Answers 3

2

Read this page http://amodernstory.com/2014/12/27/using-cors-headers-with-java-example/ and you should pay attention to this paragraph "The main idea to remember when writing your own filter is that, before any AJAX calls are made. The browser sends an OPTIONS AJAX request to the server. The server needs to reply to this OPTIONS call with the required permissions. " :D

Sign up to request clarification or add additional context in comments.

Comments

0

Your server (http://192.168.10.15:8080/) doesn't allow you to send request from external (Or just your server origin server).

You have to allow CORS (Cross-origin resource sharing) on your server, there are several ways to do it, in your server config.

Example

Comments

0

if you're using node.js & express you can allow CORS like this:

app.use(function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
    next();
});

in the express config file.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.