客户端(浏览器)如何生成发送到服务器的请求?

发布于 2024-09-30 12:25:10 字数 202 浏览 2 评论 0原文

一旦用户点击 URL,本地计算机就会在主机文件中查找是否有任何条目,如果没有,本地计算机会 ping 一些 DNS(如何?在哪里?)来解析 URL 并获取关联的 IP 地址。一旦它获得 IP,它就会在该 IP 地址上打开一个套接字通道并与服务器交互......

这准确吗?

我试图逐步详细地了解请求是如何生成并发送到服务器的。

感谢您的意见!

Once a user hits a URL the local machine does a lookup on the hosts file to see if there are any entries, if not the local machine pings some DNS (how? where?) to resolve the URL and get the associated IP address... Once it gets the IP it opens a socket channel on that IP address and interacts with the server...

Is this accurate?

I'm trying to understand step by step and in detail, how the request is generated and sent over to a server.

Thanks for your input!

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

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

发布评论

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

评论(4

最近可好 2024-10-07 12:25:10

有关 DNS 工作原理的详细概述,请参阅 RFC 1035,了解 HTTP 工作原理,请参阅RFC 2616

这些是规范文件。它们非常详细,但如果您坚持查看总体操作部分并查找需要澄清的部分,它们可能会非常有帮助。

基本上,对于您想要解释的任何协议(在更深层次上您可能想查看 TCP),获取信息最详细的地方是 RFC。

For a very detailed overview of how DNS works, see RFC 1035 and for how HTTP works see RFC 2616.

These are the canonical documents. They get very detailed, but if you stick to the Overall Operations sections and lookup those parts you need clarification on, they can be very helpful.

Basically for any protocol you want an explanation for (at a deeper level you might want to see TCP), the most detailed place to get information is the RFCs.

无悔心 2024-10-07 12:25:10

我假设你正在谈论 TCP 连接。正如您所说,客户端将在其主机文件中进行查找;如果没有条目,它将查找其第一个配置的 DNS 服务器(基于手动配置或 DHCP 设置)并启动与该服务器的连接。一旦客户端获得了所需服务器的地址,它将向该服务器发送一个 SYN 数据包,服务器将回复 SYN/ACK,客户端将回复 ACK 数据包以建立连接。这是TCP 握手。一旦建立连接,客户端和服务器就通过各自的套接字进行通信,通过 TCP 协议层传递数据并发送纠错和元数据数据包以相互协调。此信息包含请求的类型,通常取决于协议。对于 HTTP,这通常是 GET 或 POST 请求,服务器会适当地响应该请求。如果您想要更具体的信息,您可以发布您对哪种协议感到好奇吗?

I'll assume you're talking about a TCP connection. The client will, as you say, do a lookup in its hosts file; if there is not an entry, it will look up its first configured DNS server (based either on manual configuration or DHCP settings) and initiate a connection to that server. Once the client has the address of the desired server, it will send a SYN packet to that server, which will reply with a SYN/ACK, and the client will reply with an ACK packet to establish the connection. This is the TCP handshake. Once the connection is established, the client and server communicate over their respective sockets, passing data through the layers of the TCP protocol and sending error-correction and metadata packets to coordinate with each other. This information contains the type of request, usually, dependent on protocol. For HTTP, this is usually a GET or POST request, which is responded to by the server appropriately. If you want more specific information, can you post what kind of protocol you're curious about?

以歌曲疗慰 2024-10-07 12:25:10

是的。你或多或少都是正确的。

它先查看主机文件,然后查看 DNS。在 Linux 机器上,您可以更改 etc/resolv.conf 文件中的顺序。

您的主 DNS 服务器在您的 tcp/ip 设置中配置。 DNS 正在使用端口 UDP/53 来处理此类请求。如果您的 DNS 无法解析主机名,它会将其转发到父 DNS,但这是另一个主题。
获取 IP 地址后,它使用地址(IP + 端口)打开到服务器的套接字。

希望有帮助。

Yes. You ae more and less correct.

It looks on the hosts file and then in DNS. On linux machine you can change the order in etc/resolv.conf file.

Your primary DNS server is configured in your tcp/ip settings. DNS is using port UDP/53 for such requested. if your DNS can't resolve the host name it forwards it to parent DNS, but this is another topic.
After it's getting IP address it's opening socket to the server using address (IP + port).

Hope it helps.

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