Javascript 在post正文中缺少要删除的必需参数

Javascript 在post正文中缺少要删除的必需参数,javascript,node.js,axios,Javascript,Node.js,Axios,我不确定头部或主体是否配置错误。 你有没有想过是否要更改标题或者主体配置错误 const axios = require('axios'); const url = '/my_url'; const auth = { username: username, password: password }; const requestbody = { To: 'phone', From: 'phone 2' }; const headers =

我不确定头部或主体是否配置错误。 你有没有想过是否要更改标题或者主体配置错误

const axios = require('axios');
  const url = '/my_url';
  const auth = {
    username: username,
    password: password
  };

  const requestbody = {
    To: 'phone',
    From: 'phone 2'
  };

  const headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
  }
  const config = {
    auth: auth,
    headers: headers
  }

  try {
    const response = await axios.post(url, {data: requestbody}, config);
    console.log(response);
  } catch (error) {
    console.error(error);
  }
错误如下:
消息:“在帖子正文中缺少所需的参数”
您需要将参数字符串化,然后直接传递

const querystring = require('query-string');

  const query = querystring.stringify({
  To: 'phone',
    From: 'phone 2'
  });
  let options = {
    headers: {
      'Authorization': AUTH_HEADER,
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  };
    let axios_res = await post(url, query , options);
在自述文档中,它直接传递
requestbody
。试试axios.post(url、requestbody、config)