HTTP请求头部Content-Type字段

2022-04-07  本文已影响0人  xueyueshuai
  1. GET 请求
    GET 请求不存在请求实体部分,键值对参数放置在 URL 尾部,因此请求头不需要设置 Content-Type 字段
GET /index.php/api/v1_0_0.atest/test15 HTTP/1.1
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Cache-Control: no-cache
Postman-Token: eb9c600a-9538-446a-8498-02fc8f0c964d
Host: 127.0.0.1:9103
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
  1. POST 请求
    2.1 raw 原始类型,可以上传任意格式的文本,比如 text、json、xml、html、xml、javascript(中文不进行编码)
    2.1.1 text 请求
POST /index.php/api/v1_0_0.atest/test15 HTTP/1.1
Content-Type: text/plain
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Cache-Control: no-cache
Postman-Token: 38500d46-e8bb-4645-939c-1fd009b4096e
Host: 127.0.0.1:9103
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 3

123

2.1.2json 请求

POST /index.php/api/v1_0_0.atest/test15 HTTP/1.1
Content-Type: application/json
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Cache-Control: no-cache
Postman-Token: f56c1ba3-06ee-471a-9cfb-9c73fdd0f1d6
Host: 127.0.0.1:9103
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 9

{"a":"b"}

2.2:application/x-www-form-urlencoded,会将表单内的数据转换拼接成 key-value 对(非 ASCII 码进行编码)

发送 POST 请求,参数为:aaa=aaa,bbb=你的我的

POST /index.php/api/v1_0_0.atest/test15 HTTP/1.1
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Cache-Control: no-cache
Postman-Token: 90cf76d0-09ae-47cb-9d06-931ad1022670
Host: 127.0.0.1:9103
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 47

aaa=aa&bbb=%E4%BD%A0%E7%9A%84%E6%88%91%E7%9A%84

2.3
multipart/form-data,将表单的数据处理为一条消息,以标签为单元,用分隔符分开。既可以上传键值对,也可以上传文件

POST /index.php/api/v1_0_0.atest/test15 HTTP/1.1
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Cache-Control: no-cache
Postman-Token: 3b83ab6b-4da6-4a7b-b7e2-691a9368c9ba
Host: 127.0.0.1:9103
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------686669554580508856321736
Content-Length: 88812
----------------------------686669554580508856321736
Content-Disposition: form-data; name="a"

a
----------------------------686669554580508856321736
Content-Disposition: form-data; name="b"

我
----------------------------686669554580508856321736
Content-Disposition: form-data; name="c"; filename="0.jpg"

<0.jpg>
----------------------------686669554580508856321736--
上一篇下一篇

猜你喜欢

热点阅读