# Content-Type请求参数类型

# Query String Parameters

#

# application/x-www-form-urlencoded

这是表单提交的默认格式,不支持文件类型.它的请求格式是以&符号连接的键值对.(查询字符串)

POST http://www.example.com HTTP/1.1
Content-Type: application/x-www-form-urlencoded;charset=utf-8

key1=val1&key2=val2
1
2
3
4

请求参数被添加到body,需要序列化

# 参数序列化

使用qs.stringify,qs.stringify可选option indices

qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false });
// 'a=b&a=c&a=d'
1
2

# multipart/form-data

POST http://www.example.com HTTP/1.1
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryPAlLG7hJKNYc4ft3

------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="text"

demo
------WebKitFormBoundaryPAlLG7hJKNYc4ft3
Content-Disposition: form-data; name="file"; filename="demo.png"
Content-Type: image/png


------WebKitFormBoundaryPAlLG7hJKNYc4ft3--
1
2
3
4
5
6
7
8
9
10
11
12
13

# application/json

POST http://www.example.com HTTP/1.1 
Content-Type: application/json;charset=utf-8

{"name":"xfly","age": 24, "hobby":["x","xx","xxx"]}

1
2
3
4
5