Http 请求生命周期
我最近开始了 Web 应用程序后端开发人员的工作。我有点难以理解 Http 请求的生命周期。
我的理解是
- 每个 Http 请求首先联系 DNS 服务器,该服务器将请求 URL 域解析为 IP 地址。
- 获取 Web 服务器 IP 地址后,请求将转发给它(通过 PUT 请求)。像 apache 这样的网络服务器处理这个请求并将其转发给必须处理这个请求的应用程序。
在此之后,我迷失了
- 应用程序如何将响应发送给请求它的用户以及 Apcache 是否参与其中?
- 我可以使用一些调试工具在浏览器中查看整个流程吗?
- 有人可以参考一些链接来深入了解这一点吗?
I have recently started my job as web application backend developer. I am bit stuck in understanding lifecycle of a Http request.
What I understood is
- Every Http request first contacts a DNS server which resolves the request URL domain to a IP address.
- After fetching the Webserver IP address request is forwarded to it(via PUT request). A webserver like apache handles this request and forwards this to application which has to handle this.
After this I am lost with
- How response is sent by the application to the user who requested it and will Apcache involved in this?
- Can I see the entire flow in my browser with some debugging tools?
- Can someone refer some links to understand this in depth?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我觉得你的理解有点错误。
如果您访问 www.google.com(不使用任何表单,只是想要该网站),这就是发生的情况:
GET / HTTP/1.1 Host: www.google.com
GET、PUT、POST、DELETE 等是 HTTP 请求方法。它们具有特殊含义,您可以在 RFC 中看到它们。
Cookie 通常用于在多个 HTTP 请求(称为会话)中识别同一用户。因此,这些 cookie 称为会话 cookie。
您可以使用网络嗅探器工具调试通信,例如 Wireshark。 Firefox 有一个名为 Tamper Data 的第三方插件,它可以在将请求发送到服务器之前更改请求。
HTTP RFC 是了解其工作原理的良好来源。
I think you are a bit wrong on your understanding of it.
If you go to www.google.com (not using any forms, just wanting the site), this is what happens:
GET / HTTP/1.1 Host: www.google.com
GET, PUT, POST, DELETE and others are HTTP request methods. They have special meaning which you can see in the RFC.
Cookies are commonly used to identify the same user across multiple HTTP requests, called sessions. Therefore these cookies are called session cookies
You can debug the communication by using a network sniffer tool, for example Wireshark. Firefox has a third party plugin called Tamper Data that can change the request before they are sent to the server.
The HTTP RFC is a good source of how it all works.
当服务器收到浏览器的请求时,浏览器会被绑定到主机上的某个端口,浏览器的IP地址和端口号将被附加到发送到服务器的请求中。服务器将响应发送到 IP 地址和端口号
while server receives the request from browser , the browser will be binded to some port on the host , ip address and port number of browser will be attached with the request that sends to server. server sends the responce to the ip address and port number
这是各种基于产品的公司中常见的面试问题之一。
HTTP 是一种请求-响应协议。例如,用户代理通常通过打开到主机上特定端口(默认为端口 80)的 TCP/IP 连接来向服务器发起请求。请求本身包括:
请求行、
一组请求标头,以及
一个实体。
侦听该端口的 HTTP 服务器等待客户端发送请求消息。收到请求后,服务器发送响应,其中包括:
状态行,
一组响应标头,以及
一个实体。
请求或响应中的实体可以简单地视为有效负载,它可以是二进制数据。其他项目是可读的 ASCII 字符。当响应完成后,浏览器或服务器可以终止 TCP/IP 连接,或者浏览器可以发送另一个请求。
This is among the popular interview questions asked in various product based companies.
HTTP Is a request-response protocol. For example, a user agent initiates a request to a server, typically by opening a TCP/IP connection to a particular port on a host (port 80 by default). The request itself comprises:
a request line,
a set of request headers, and
an entity.
An HTTP server listening on that port waits for the client to send a request message. Upon receiving the request, the server sends a response that comprises:
a status line,
a set of response headers, and
an entity.
The entity in the request or response can be thought of simply as the payload, which may be binary data. The other items are readable ASCII characters. When the response has been completed, either the browser or the server may terminate the TCP/IP connection, or the browser can send another request.
我发现此资源对于理解
HTTP 生命周期
期间采取的步骤非常有帮助:实际上非常有趣,但不知道所有中间步骤,尤其是在确定IP 时进行缓存检查URL 的地址
。https://medium.com/@maneesha.wijesinghe1/what-happens-when-you-type-an-url-in-the-browser-and-press-enter-bb0aa2449c1a
I found this resource very helpful in understanding the steps taken during the
HTTP lifecycle
: quite interesting actually though, wasn't aware of all the intermediate steps especially w/the cache checking when determining theIP Address
of a URL.https://medium.com/@maneesha.wijesinghe1/what-happens-when-you-type-an-url-in-the-browser-and-press-enter-bb0aa2449c1a