【问题标题】: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.

我是对的还是有其他步骤?

【问题讨论】:

  • 这个answer 有很好的解释。
  • 谢谢,这是一个很好的答案。

标签: sockets http http-headers


【解决方案1】:

你是对的,它就是这么简单,但语法上并不死板。

  1. 如果不是 IP 则解析域(DNS 查询)
  2. 如果不是 SSL 并且没有被冒号覆盖,则默认打开端口 80 (http://host:port/)
  3. 为 http://host/uri/here?other=stuff&too 发送请求 (#1)
  4. 接收响应 (#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.

【讨论】:

  • 谢谢,这是一个很好的答案。
猜你喜欢
  • 1970-01-01
  • 2012-01-26
  • 2019-10-12
  • 1970-01-01
  • 1970-01-01
  • 2012-10-07
  • 2020-10-17
  • 1970-01-01
  • 2020-11-26
相关资源
最近更新 更多