0

Client side : AngularJS

Server / tech : Apache / Java Spring

First error was the No Access Control Allow Origin header not present. We fixed that by adding this code to the server side. The request is working fine with postman.

In Controller function http get method is returning error 401 (Unauthorized).

$http.get("our_local_url").then(function(data) {
                console.log("data:"+data);
            }, function(error) {
                console.log("error:"+error);
            });

A Test page with Jquery Ajax Call is working fine with the code

$.ajax({
        url: "our_local_url",
        type: "GET",
        success: function(result){
            console.log(result);
        },
        error: function(xhr,status,error){
            console.log(error);
        }
});

I've gone through several SO answers before asking this.

Monster Brain
  • 1,950
  • 18
  • 28

2 Answers2

0

Add withCredentials: true in service call

try this below

$http.get("our_local_url", { withCredentials: true }).then{...};
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • Thanks for the suggestion. However trying that code doesn't help. Still showing the same error with angular. working fine with jquery ajax. – Monster Brain Sep 15 '18 at 06:32
0

There was some security handling in the spring-security which was blocking the call. After it's removed, it worked (No Access Control Allow Origin header added).

Monster Brain
  • 1,950
  • 18
  • 28