HTTP 协议基础

HTTP 协议基础

  • 一次请求

  • 报文

一次请求

#curl -v -d '{"str_info":"meetbill"}' "http://127.0.0.1:8585/x/hello"
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8585 (#0)
> POST /x/hello HTTP/1.1
> Host: 127.0.0.1:8585
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 23
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 23 out of 23 bytes
< HTTP/1.1 200 OK
< meetbill: 1.0.1
< Content-Length: 38
< butterfly: 1.0.5
< x-reqid: EDD1FFCB01842079
< x-cost: 0.008146
< Date: Sun, 20 Oct 2019 12:21:05 GMT
< Server: XXXXXXXXX
<
* Connection #0 to host 127.0.0.1 left intact
{"stat": "OK", "str_info": "meetbill"}

报文

http 是典型的报头 + 报体的这个一个约定格式。

  • 通过 \r\n\r\n 来区分报头和报体

  • 报头通过 \r\n 来区分不同的信息

看个示例

CRLF

理解 TCP 流的概念及粘包的现象

Last updated