How to post query parameters with Axios?(如何使用 Axios 发布查询参数?)
问题描述
我正在尝试使用一些查询参数在 API 上发帖.当我尝试通过将邮件和名字作为查询参数传递时,这适用于 PostMan/Insomnia :
I am trying to post on an API with some query params. This is working on PostMan / Insomnia when I am trying to by passing mail and firstname as query parameters :
http://localhost:8000/api/mails/users/sendVerificationMail?mail=lol%40lol.com&firstname=myFirstName
但是,当我尝试使用 React Native 应用程序执行此操作时,出现 400 错误(查询参数无效).
However, when I am trying to do it with my react native app, I got a 400 error (Invalid Query Parameters).
这是post方法:
.post(`/mails/users/sendVerificationMail`, {
mail,
firstname
})
.then(response => response.status)
.catch(err => console.warn(err));
(我的邮件和名字在控制台中记录如下:lol@lol.com
和 myFirstName
).
(my mail and firstname are console.logged as follow: lol@lol.com
and myFirstName
).
所以我不知道如何在我的请求中使用 Axios 传递查询参数(因为现在,它正在传递 data: { mail: "lol@lol.com", firstname: "myFirstName" }代码>.
So I don't know how to pass Query Parameters with Axios in my request (because right now, it's passing data: { mail: "lol@lol.com", firstname: "myFirstName" }
.
推荐答案
axios 签名为 axios.post(url[, data[, config]])
.所以你想在第三个参数中发送 params 对象:
axios signature for post is axios.post(url[, data[, config]])
. So you want to send params object within the third argument:
.post(`/mails/users/sendVerificationMail`, null, { params: {
mail,
firstname
}})
.then(response => response.status)
.catch(err => console.warn(err));
这将发布一个带有两个查询参数的空主体:
This will POST an empty body with the two query params:
发布http://localhost:8000/api/mails/users/sendVerificationMail?mail=lol%40lol.com&firstname=myFirstName
这篇关于如何使用 Axios 发布查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Axios 发布查询参数?


基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01