How can I add raw data body to an axios request?

前端 未结 8 1120
情歌与酒
情歌与酒 2020-12-30 19:44

I am trying to communicate with an API from my React application using Axios. I managed to get the GET request working, but now I need a POST one.

I need the body to

相关标签:
8条回答
  • 2020-12-30 20:09

    You did this in my project

     axios({
      method: "POST",
      url: "https://URL.com/api/services/fetchQuizList",
      headers: {
        "x-access-key": data,
        "x-access-token": token
      }
       data: {
         quiz_name: quizname,
    
       }
    })
      .then(res => {
        console.log("res", res.data.message);
    
      })
      .catch(err => {
        console.log("error in request", err);
      });
    

    This should help

    0 讨论(0)
  • 2020-12-30 20:13

    How about using direct axios API?

    axios({
      method: 'post',
      url: baseUrl + 'applications/' + appName + '/dataexport/plantypes' + plan,
      headers: {}, 
      data: {
        foo: 'bar', // This is the body part
      }
    });
    

    Source: axios api

    0 讨论(0)
提交回复
热议问题