当前位置:网站首页>数据提交类型 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” 类型 |
边栏推荐
- Two week learning results of machine learning
- Insight into mobile application operation growth in 2022 white paper: the way to "break the situation" in the era of diminishing traffic dividends
- Leetcode 115. different subsequences
- Observer mode
- Traffic is not the most important thing for the metauniverse. Whether it can really change the traditional way of life and production is the most important
- A scene application of 2D animation
- Analysis of the calling principle of Changan chain solid smart contract
- [computer explanation] what should I pay attention to when I go to the computer repair shop to repair the computer?
- Dart final and const variables
- labelme标注不同物体显示不同颜色以及批量转换
猜你喜欢

Yolov7 model reasoning and training its own data set

大话西游服务端启动注意事项

【terminal】x86 Native Tools Command Prompt for VS 2017

容器内组播

Basic usage of thread class

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

Baidu xirang's first yuan universe auction ended, and Chen Danqing's six printmaking works were all sold!

30 times performance improvement -- implementation of MyTT index library based on dolphin DB

Statistical learning -- naive Bayesian method

YOLOv7模型推理和训练自己的数据集
随机推荐
【SemiDrive源码分析】【驱动BringUp】38 - NorFlash & eMMC分区配置
Wechat applet switchtab transmit parameters and receive parameters
10分钟看懂Jmeter 是如何玩转 redis 数据库的
睡眠不足有哪些危害?
Observer mode
容器内组播
QT actual combat case (53) -- using qdrag to realize the drag puzzle function
Octopus network community call 1 starts Octopus Dao construction
[computer explanation] NVIDIA released geforce RTX Super Series graphics cards, and the benefits of game players are coming!
杜教筛
ArgoCD 用户管理、RBAC 控制、脚本登录、App 同步
Example demonstration of math.random() random function
How to learn C language?
Introduction to bridging mode and sharing mode
js数据类型的判断——案例6精致而优雅的判断数据类型
Cointegraph wrote: relying on the largest Dao usdd to become the most reliable stable currency
健康打卡每日提醒累了?那就让自动化帮你---HiFlow,应用连接自动化助手
Purpose of SQL square brackets
RecycleView实现item重叠水平滑动
Leetcode 115. different subsequences