浏览器/服务器如何协同工作来显示 html 页面?

发布于 2024-09-30 21:22:41 字数 242 浏览 2 评论 0原文

我经常被问到这个问题=/

但我只知道如何在非常高的水平上回答它。

从用户输入 URL 并按回车键的那一刻起,客户端和服务器端会发生什么,请求/响应如何工作?服务器如何与 CGI/解释器交互?

如果您可以将我引导至包含此详细信息的 URL,或者您可以回答该问题,也会很有帮助。

当我向人们描述这一点时,我总觉得他们在寻找细节,而我没有提供足够的细节。

谢谢!

I get this question a lot =/

But I only know how to answer it at a very high level.

From the minute a user enters a URL and hits enter, what happens on the client and server side, and how do requests/responses work? How does the server interact with CGI/interpreters?

It would be helpful too if you could direct me to a URL that has this information in detail, or if you can answer it.

When I describe this to people I always feel like theyre looking for specifics and I'm not giving enough detail.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无可置疑 2024-10-07 21:22:41
  1. 客户端发起通信(通常是 HTTP GET 请求),
  2. 服务器接收 REQUEST-HEADER 并解析其中包含的 URL。
  3. 服务器会进行查找以查看硬盘文件夹中是否存在本地匹配的 URL。如果网络服务器像 Microsoft IIS 一样处理虚拟服务器,那么它将在从 REQUEST 标头中检索“www.domain.com”部分后确定要搜索的文件夹。
  4. 如果找到网络文档(HTML 文件),则服务器将其作为响应 + HTTP 状态代码发送回(例如,200 表示:已找到,此请求顺利进行,而 404 表示“未找到该文件”)
  5. 客户端(浏览器) ) 收到 RESPONSE 并且现在可以按需要显示它。如果它包含渲染引擎,那么它将搜索模式(HTML 标签或任何语言),然后按原样显示。

这也称为“无状态”,因为服务器在客户端收到响应流中的所有内容后关闭与客户端的通信。

因此,服务器无法知道客户端是否仍然连接,也无法知道客户端是否稍后返回。许多服务器确实使用 cookie 或类似的方式提供会话对象,以跟踪发送下一个 REQUEST 的客户端是否相同,如果是,则允许更“智能”的服务器响应 - 例如查找、事务和登录。

  1. Client initiates communication (Usually a HTTP GET request)
  2. Server receives REQUEST-HEADER and parses the URL contained within.
  3. Server does a lookup to see if any URL matches locally in a harddrive-folder. If the webserver handles virtual servers like a Microsoft IIS, then it will determin which folder to search after retrieving the "www.domain.com" part from the REQUEST header.
  4. If web-document (HTML file) is found, then Server sends this back as RESPONSE + a HTTP status code (eg. 200 saying: found, this request went well, where as 404 is "didnt find that file")
  5. Client (browser) receives RESPONSE and can now display it as it wants. If it contains a render engine, then it will search for patterns (HTML tags or whatever language) and then display it as such.

This is also called "stateless" as the server closes communication with client after the client has received everything from the reponse-stream.

Therefore the server cannot know if the client is still connected nor if its comming back later. Many servers does provide a session object using cookies or similar to track if its the same client that sends the next REQUEST and if so, allowing more "intelligent" server responses - such as seeking, transactions and logins.

¢蛋碎的人ぎ生 2024-10-07 21:22:41

客户端向服务器发送请求标头(通过 DNS 查找 IP)。

服务器软件(例如 Apache)在需要时调用 CGI 并准备响应。

它发送回标头以及内容。

The client sends request headers to the server (finds the IP via DNS).

The server software (e.g. Apache) calls CGI if it needs to and prepares the response.

It sends headers back as well as the content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文