0

I would like to send the value to the spring boot through the header using the http put method in React.

So I made an api call code by using axios.

import axios from 'axios';
import {hashPwd} from '../../login/presentation/Encryptpwd'

export async function  ChangeNewPwd(newPwd) {
    alert(newPwd);
    const hash = hashPwd(sessionStorage.getItem("memberHash")+newPwd);
    alert(hash);
    let result;
    return await axios.put("/member/pwd",{
        headers: {
            Authorization:hash
        }
    })
    .then(function(res){
        result = res.data;
        return result;        
    })
    .catch(function(error){
        console.log(error);
        result = 500;
        return result;
    })
}

But spring boot cannote read header value and sending this error

w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingRequestHeaderException: Required request header 'Authorization' for method parameter type String is not present]

I have no idea why I'm getting this error. How can I solve this problem?

I'll show my spring boot code below.

    @PutMapping("/pwd")
    public int updatePwd(@RequestHeader("Authorization") String autho){
        logger.info("Changing pwd!!!");
        logger.info(autho);
        return 500;
    }

1 Answer 1

1

I think the headers need to be passed in the third argument of the put method. The second argurment is for the data to be sent in the body.

await axios.put("/member/pwd", null, {
  headers: { Authorization: hash }
})
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.