实际上,HTTP的body可以是二进制数据,也可以是文本。HTTP协议本身不对body内容的格式做限制,具体格式取决于Content-Type
头字段的定义。
文本数据:
-
当Content-Type头字段指定为文本类型时(如
text/plain
、text/html
、application/json
等),HTTP body中的内容通常是文本数据。 -
例如:
Content-Type: text/plain This is a plain text message.
Content-Type: application/json { "name": "John", "age": 30 }
请求发送
JSON
数据:POST /api/data HTTP/1.1 Host: example.com Content-Type: application/json Content-Length: 48 { "username": "john_doe", "email": "john@example.com" }
二进制数据:
-
当Content-Type头字段指定为二进制类型时(如
application/octet-