当前位置:网站首页>qs. In the stringify interface, the input parameter is converted into a & connected string (with the application / x-www-form-urlencoded request header)
qs. In the stringify interface, the input parameter is converted into a & connected string (with the application / x-www-form-urlencoded request header)
2022-04-23 07:04:00 【NOyesNONO_】
Basic format
import request from '@/utils/request';// It mainly does some unified encapsulation processing for requests , The use of axios
import qs from 'qs';
export function xxxapi(data) {
return request({
url: 'xxx/xxx/xxx',
headers: {
'content-type': 'application/x-www-form-urlencoded' },
method: 'post',
data: qs.stringify(data)
})
}
Network display
Format of request header and response header

Submit load
The request payload is submitted as a form , With & The string of the connection

After the browser compiles and formats :

Interface to return json Format

The input parameter contains complex data types , Be careful Json Convert to string , Otherwise, the report will be wrong
When qs.stringify Encountered complex data types , Set objects as many as possible :
{
aaa:[{
name:'test',
age:20
}]
}
Displayed in the request as :


At this time, the interface will report an error (500), Because the interface that submits the form should have received variables aaa, But after treatment, it becomes aaa[0][name], Cannot match interface correctly . So when you encounter complex data types , First pass through JSON.stringify() Convert to string .
other
If only application/x-www-form-urlencoded no need qs.stringify Handle data The input parameter format is as follows :

With application/json Format request

detailed application/json and application/x-www-form-urlencoded difference
版权声明
本文为[NOyesNONO_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230601164949.html
边栏推荐
- 2021年国产数据库12强介绍
- Kids and COVID: why young immune systems are still on top
- 【漏网之鱼】Ansible AWX调用playbook传参问题
- Thanos Compactor组件使用
- switch case时连写常规判断表达式的错误 case和if并用 l
- Concurrent optimization request
- Openvswitch compilation and installation
- 【OSS文件上传快速入门】
- 异常记录-16
- Construire un blog Cloud basé sur ECS (bénédiction sur le Code Cloud Xiaobao, explication détaillée de la tâche iphone13 gratuite)
猜你喜欢
随机推荐
Prometheus Thanos快速指南
memcached 源码分析
基于DPDK实现VPC和IDC间互联互通的高性能网关
prometheus告警记录持久化(历史告警保存与统计)
LeetCode刷题|13罗马数字转整数
Prometheus Thanos与Cortex组件比较
异常记录-18
Oracle Net Service:监听器与服务名解析方法
使用prom-label-proxy实现Prometheus Thanos的基于标签的多租户读
tc ebpf 实践
异常记录-17
OVS and OVS + dpdk architecture analysis
SQL学习|复杂查询
异常记录-19
Web登录小案例(含验证码登录)
XDP类型的BPF程序
Get DOM element location information by offset and client
用反射与注解获取两个不同对象间的属性值差异
virtio 与vhost_net介绍
[fish in the net] ansible awx calls playbook to transfer parameters







