当前位置:网站首页>数据提交类型 Request Payload 与 Form Data 的区别总结
数据提交类型 Request Payload 与 Form Data 的区别总结
2022-07-25 07:03:00 【清风细雨_林木木】
大纲
1.什么是`Request Payload`,什么是`Form Data`
2.不同的`Content-Type`对应不同的提交方式
3.总结
图形:
1.什么是Request Payload,什么是Form Data
Request Payload (http请求体模式)
Form Data (表单请求体模式)
Request Payload 对应:
Content-Type:application/json
Form Data 对应:
Content-Type: application/x-www-form-urlencoded
和
Content-Type: multipart/form-data
备注:表单(POST请求)的编码
<form action="/xxxx" method="get" enctype="application/x-www-form-urlencoded"><form action="/xxxx" method="get" enctype="multipart/form-data"><form action="/xxxx" method="get" enctype="text/plain">
| 类型 | 含义 |
|---|---|
| application/x-www-form-urlencoded | 默认编码方式, 将数据编码成键值对形式 |
| multipart/form-data | 表单文件上传 |
| text/plain | 字符串型,数据获取方式 getInputStream |
2.不同的Content-Type对应不同的提交方式
数据传输中一般类型只有3种
1.Content-Type: text/plain
2.Content-Type: application/x-www-form-urlencoded
3.Content-Type: application/json
传统
ajax请求方式Content-Type:text/plain
function submit2() {
var xhr = new XMLHttpRequest();
xhr.timeout = 3000;
var obj = {
a: 1, b: 2};
xhr.open('POST', '/');
xhr.send(obj);
}
需要通过xhr.send(JSON.stringify(obj)) 修改为字符串后进行传输。
Content-Type: text/plain
Request Payload: #字符串
axios方式请求Content-Type:application/json 和 Content-Type: application/x-www-form-urlencoded
function submit3() {
var sence1 = 'name=123&val=456';
var sence2 = {
name: 123, val: 456};
axios.post('/', sence1)
}
# 请求数据为“字符”时:
Content-Type: application/x-www-form-urlencoded
Form Data: #name=123&val=456
# 请求数据为“对象”时:
Content-Type:application/json
Request Payload: #{name:123,vla:456}
Form表单提交
<form action="/" method="POST">
<input name="name" type="text">
<input name="password" type="text">
<button>提交</button>
</form>
Content-Type: application/x-www-form-urlencoded
Form Data: # name='xxx'&password='yyy'
3.总结
Content-Type的差异
| 模式 | 类型 |
|---|---|
| ajax | Content-Type默认为 “文本” 类型 |
| form提交 | Content-Type默认为 “Form” 类型 |
| axios传递字符串 | Content-Type默认为 “Form” 类型 |
| axios传递对象 | Content-Type默认为 “JSON” 类型 |
边栏推荐
- CodeForces 1417B Two Arrays
- Yolov7 model reasoning and training its own data set
- Discuss the important factors that affect the success or failure of automated testing
- Restrict Su command and sudo mechanism to promote nmap and console command netstat
- 大话西游服务端启动注意事项
- 微信小程序switchTab传参以及接收参数
- 机器人工程-教学品质-如何判定
- LeetCode46全排列(回溯入门)
- Analysis of the calling principle of Changan chain solid smart contract
- Software engineering in Code: regular expression ten step clearance
猜你喜欢

2022 Shenzhen cup

Health clock in daily reminder tired? Then let automation help you -- hiflow, application connection automation assistant
![[Yugong series] July 2022 go teaching course 016 logical operators and other operators of operators](/img/36/9ad3f76078153f6af6c5b59d99564a.png)
[Yugong series] July 2022 go teaching course 016 logical operators and other operators of operators

Rambus announces ddr5 memory interface chip portfolio for data centers and PCs

常吃发酵馒头是否会伤害身体

使用 Web API 上传和下载多个文件

CTF Crypto---RSA KCS1_ Oaep mode

Microorganisms are healthy. Don't exclude microorganisms in the human body

Statistical learning -- naive Bayesian method

Thread 类的基本用法
随机推荐
【SemiDrive源码分析】【驱动BringUp】38 - NorFlash & eMMC分区配置
Standard C language 89
【电脑讲解】去电脑维修店修电脑需要注意什么?
[semidrive source code analysis] [drive bringup] 38 - norflash & EMMC partition configuration
【transformer】DeiT
Rongyun launched a real-time community solution and launched "advanced players" for vertical interest social networking
Can interface debugging still play like this?
Hierarchical reinforcement learning: a comprehensive survey
[daily question] sword finger offer II 115. reconstruction sequence
[Yugong series] July 2022 go teaching course 015 assignment operators and relational operators of operators
Enable the free pan domain SSL certificate for kubesphere cluster and realize the automatic update and distribution of certificates
vulnhub CyberSploit: 1
Leetcode sword finger offer brush question notes
2022深圳杯
[computer explanation] NVIDIA released geforce RTX Super Series graphics cards, and the benefits of game players are coming!
Leetcode 115. different subsequences
Builder pattern
Analysis of the calling principle of Changan chain solid smart contract
A little consideration of strategic mode
The ultimate difference between MVC and three-tier architecture