简体   繁体   中英

Missing required parameter To in the post body

I'm not sure if the header or the body are configured incorrectly. Any thoughts on whether to change the headers or maybe the body is misconfigured?

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

Error like: message: 'Missing required parameter To in the post body'

you need to stringify parameters and then pass directly

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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