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 发布查询参数?
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
