2

How do I retrieve Authorization header from HttpHeaders? there is no matching method like the rest of the headers. I manged to get it like -

HttpHeaders headers = sendPost.getHeaders();
List<String> list = headers.get(JwtFilterLogin.HEADER_AUTH); //header key - Authorization
System.out.println(list.get(0)); //the value

Is there a better way?

1 Answer 1

3

Yes.

Your "get first value" logic is already provided by HttpHeaders#getFirst() . Furthermore , Authorization header field name is also provided by HttpHeaders.AUTHORIZATION such that you do not need to define by your own :

HttpHeaders headers = sendPost.getHeaders();
String value = headers.getFirst(HttpHeaders.AUTHORIZATION);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.