reactjs - 如何使用 Axios 将对象作为 QueryString 传递给 web api
问题描述
我是 Axios 的新手,在这个简单的问题上遇到了问题。
我的反应代码:
const params = {
"id": "1",
"name":"Mike"
};
axios.request({
url: 'https://localhost:44343/api/SampleData/test',
method: 'get',
data:params
})
我的 asp.net 核心 web api:
[HttpGet("test")]
public async Task Test([FromQuery]Model model)
我的模型:
public class Model
{
public string Id { get; set; }
public string Name { get; set; }
}
我未能将 js 对象作为查询字符串传递给我的 api 代码。和model
的数据为空。Id
Name
解决方案
我找到了解决方案:
const querystring = require('querystring');
const params = {
"id": "1",
"name":"Mike"
};
axios.request({
url: 'https://localhost:44343/api/SampleData/test?' + querystring.stringify(params),
method: 'get',
data:params
})
推荐阅读
- python - 没有通过 Pytorch 更新线性回归中的偏差
- html - 仅显示背景图像的顶部
- python - 赋值前引用的局部变量“intent”
- python - 通过pandas为excel中的某些单元格添加颜色 - python
- sql - 带有连接和动态表名的更新语句
- kubernetes - 使用 GKE 处理流量突然增加(多个数量级)
- amazon-s3 - Python Meta Client Copy 403 Head Object Forbidden
- node.js - 在远程机器上的 docker 容器中运行进程时是否可以挂载主机文件夹
- azure-devops - 使用 Azure Dacpac 任务时释放管道错误
- asp.net-core-mvc - 如何使用 Swashbuckle.AspNetCore.Swagger 在 asp.net 核心中忽略/更改模型参数