HTTP协议的工作原理有多严格?

时间:2014-01-04 07:35:01

标签: sockets http http-headers

我想知道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.

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

1 个答案:

答案 0 :(得分:1)

你是对的,虽然没有死在语法上,但这很简单。

  1. 如果不是IP(DNS查询),则解析域
  2. 默认情况下打开端口80,如果不是SSL而不是冒号覆盖(http:// host:port /)
  3. 发送请求(#1)为http:// host / uri / here?other = stuff& too
  4. 收到回复(#2)
  5. 示例请求:(#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.