Passing headers with axios POST request

后端 未结 9 1904
青春惊慌失措
青春惊慌失措 2020-11-28 20:27

I have written an axios POST request as recommended from the npm package documentation like:

var data = {
    \'key1\': \'val1\',
    \'key2\': \'val2\'
}
ax         


        
9条回答
  •  被撕碎了的回忆
    2020-11-28 20:55

    This might be helpful,

    const data = {
      email: "me@me.com",
      username: "me"
    };
    
    const options = {
      headers: {
          'Content-Type': 'application/json',
      }
    };
    
    axios.post('http://path', data, options)
     .then((res) => {
       console.log("RESPONSE ==== : ", res);
     })
     .catch((err) => {
       console.log("ERROR: ====", err);
     })
    Note: All status codes above 400 will be caught in the Axios catch block. Also, headers are optional for the post method in Axios

    Blockquote

    Blockquote

提交回复
热议问题