[英]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'
错误如: 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.