我正在尝试在 API 上发布一些查询参数。
当我尝试通过邮件和名字作为查询参数传递时,这正在 PostMan / Insomnia 上工作:
http://localhost:8000/api/mails/users/sendVerificationMail?mail=lol%40lol.com&firstname=myFirstName
但是,当我尝试使用 React Native 应用程序执行此操作时,出现 400 错误(查询参数无效)。
这是帖子方法:
.post(`/mails/users/sendVerificationMail`, {
mail,
firstname
})
.then(response => response.status)
.catch(err => console.warn(err));
(我的邮件和名字是 console.logged 如下:[email protected] /cdn-cgi/l/email-protection
and myFirstName
).
所以我不知道如何在我的请求中使用 Axios 传递查询参数(因为现在,它正在传递data: { mail: "[email protected] /cdn-cgi/l/email-protection", firstname: "myFirstName" }
.
帖子的 axios 签名是axios.post(url[, data[, config]])
。所以你想在第三个参数中发送 params 对象:
.post(`/mails/users/sendVerificationMail`, null, { params: {
mail,
firstname
}})
.then(response => response.status)
.catch(err => console.warn(err));
这将发布一个带有两个查询参数的空正文:
POST
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)