0

I am sending from my server (SpringBoot) a cumstom header ->>

SpringBoot:

        response.addHeader("headerToken", "valueToken");
        response.addHeader("Access-Control-Allow-Origin","*");
        response.addHeader("Access-Control-Allow-Methods","GET");     
        response.setHeader("Access-Control-Expose-Headers","Custom-Header");
        return new ModelAndView("redirect:" + url);

My return is "http://...path...AngularJS...etc"

My flow doesn't AngularJS call SpringBoot and return AngularJS, so, I can't do ->

$http.get('Springboot').
  success(function(data, status, headers, config) {
    ...
  })
  .error(function(data, status, headers, config) {
    ...
  });

How my flow doesn't AngularJS->Springboot->AngularJS I can't get headers in my http.succes... from AngularJS.

Then I thinked get headers in my controller with JS ->

 angular.module('don').controller('Dona', ['$rootScope', '$scope', '$http', '$cookies', '$routeParams', '$window', '$location', function ($rootScope, $scope, $http, $cookies, $routeParams, $window, $location) {
        var self = this;
        var req = new XMLHttpRequest();
        req.open('GET', document.location, false);
        req.send(null);
        var headers = req.getAllResponseHeaders().toLowerCase();
        console.log(headers);
        console.log("---");
        req .addEventListener("readystatechange", function () {
        if (this.readyState == this.HEADERS_RECEIVED)
            console.log(this.getAllResponseHeaders())
         });
      console.log("***");

// Load get data
     ...etc
    }]);

(this.readyState is null)

The result is ->

https://i.stack.imgur.com/mDpGS.png

I need 10 repu for show imgYou can see that I added -> response.setHeader("Access-Control-Expose-Headers","Custom-Header"); ...

how I can read the my valueToken ?

See this img pls->

https://i.stack.imgur.com/LmfXK.png

(I need 10 repu for show img)

Eduardo
  • 47
  • 1
  • 7
  • Answer from this question might be help for u. https://stackoverflow.com/questions/15042439/cant-get-custom-http-header-response-from-ajax-getallresponseheaders – Dongeon Kim Apr 05 '19 at 08:42
  • I added response.addHeader("Access-Control-Allow-Origin","*"); response.addHeader("Access-Control-Allow-Methods","GET"); in my server and nothing.. – Eduardo Apr 05 '19 at 08:58
  • In my server I had this, I add before "return", read my post. – Eduardo Apr 05 '19 at 10:15

0 Answers0