Unable to read custom http headers in javascript onreadystatechange?

后端 未结 2 863
南方客
南方客 2021-01-14 20:18

While i am trying to read custom http headers.i am hetting null.

Jersey authentication resource :-

   @Path(\"/redirect\")
   public class RedirectDe         


        
相关标签:
2条回答
  • 2021-01-14 20:31

    If someone still looking for the answer, you need to set "Access-Control-Expose-Headers" along side with the response. In example :

    Access-Control-Expose-Headers: Content-Type,Authorization,X-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-Reset
    
    0 讨论(0)
  • 2021-01-14 20:49

    change your callback:

    xhr.onreadystatechange = function() {
          if(xhr.readyState == 4){//if you are looking only for HTTP 200, then add condition xhr.status == 200
             console.log(xhr.getResponseHeader("Authorization"));//will get your response header
             window.location.href = xhr.responseURL;//Redirect works
          }
      }
    

    Note: readyState Holds the status of the XMLHttpRequest. Changes from 0 to 4:

    0: request not initialized

    1: server connection established

    2: request received

    3: processing request

    4: request finished and response is ready

    0 讨论(0)
提交回复
热议问题