繁体   English   中英

帖子正文中缺少必需的参数 To

[英]Missing required parameter To in the post body

我不确定标题或正文是否配置不正确。 关于是否更改标题或主体配置错误的任何想法?

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);
  }

错误如: message: 'Missing required parameter To in the post body'

你需要对参数进行字符串化,然后直接传递

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM