I'm using SpringBoot Rest Template to for an API call. I have a requirement that the authorization header not be in the code. It should be added from somewhere outside. I'm trying to do this via Postman, but whenever I add the authorization header and make the call, SpringBoot says: "header 'authorization' is required"
Is it possible to inject headers from Postman into my code to make the call? I've included a code snippet of what I'm trying to do
I am inheriting this code from someone else. This isn't my area of expertise, so there may be something really obvious that I'm missing here.
HttpHeaders headers = createHeaders();
HttpEntity<String> request = new HttpEntity<String>(headers);
ResponseEntity<String> response = restTemplate.exchange(Url, HttpMethod.POST, request, String.class);
private HttpHeaders createHeaders() {
return new HttpHeaders() {
/**
*
*/
private static final long serialVersionUID = 1L;
{
set("accept", "application/json");
set("content-type", "application/json");
//setContentType(MediaType.APPLICATION_JSON);
setCacheControl("no-store");
}
};
}
question from:
https://stackoverflow.com/questions/65945544/pass-headers-from-postman-to-springboot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…