Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

spring boot - Pass Headers from Postman to Springboot

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...