【问题标题】:How exacty HTTP protocol works? [duplicate]HTTP 协议究竟是如何工作的? [复制]
【发布时间】:2023-03-16 22:52:01
【问题描述】:
先生,我想知道 http 是如何工作的。当您在浏览器中键入“www.youtube.com”时,会出现以下步骤。
- DNS look-up for "www.youtube.com" (suppose you get 1.1.1.1)
- Open socket to 1.1.1.1 port=80 and send a GET HTTP packet on it.
- Receive a response on that socket.
我是对的还是有其他步骤?
【问题讨论】:
标签:
sockets
http
http-headers
【解决方案1】:
你是对的,它就是这么简单,但语法上并不死板。
- 如果不是 IP 则解析域(DNS 查询)
- 如果不是 SSL 并且没有被冒号覆盖,则默认打开端口 80 (http://host:port/)
- 为 http://host/uri/here?other=stuff&too 发送请求 (#1)
- 接收响应 (#2)
示例请求:(#1) 使用并且必须以两个回车换行 (CrLf) 结束
GET /uri/here?other=stuff&too HTTP/1.1
Host: host
Other: Headers, too. Such as cookies
Header: Value
示例响应:(#2)
HTTP/1.1 200 OK
Other: Headers, too. Such as cookies
Header: Value
<html>Actual HTTP payload is here, could be HTML data, downloaded file data, etc.