- Your browser extracts the: "scheme"/protocol, host, optional port number, resource path, and query strings.
- Now that the browser has the intended hostname for the request, it needs to resolve an IP address.
- then the browser look through its own cache of recently requested URLs, the operating system’s cache of recent queries, your router’s cache, and your DNS cache.
-
If the cache lookup fails (we will assume it does), your browser fires off a DNS request using UDP.
-
Your request will now have to travel many network devices to reach its target DNS server.
-
Once your request arrives at your configured DNS server, the server looks for the address associated with the requested hostname.
- If it finds one, it sends a response.
- If, on the other hand, the DNS server you have targeted cannot locate the given hostname, it passes the request along to another DNS server it is configured to defer to.
- This happens recursively until the address is found, or an "authoritative" nameserver is hit.
- If an address for the given domain cannot be resolved, the server responds with a failure and your browser returns an error.
-
If the response makes it back the requesting client now has a target IP.
-
One of the key differences between TCP and UDP is that TCP ensures delivery and ordered data transmission.
-
what’s most relevant is that TCP connections are opened using what’s known as a three-way handshake. The server must already be "listening" on a port, performing a passive open, after which the client can initiate an active open, and the handshake works as follows:
- The client initiates the active open by sending a
SYN
"control" packet to the server. - The server responds with a
SYN-ACK
message, which contains an acknowledgement number for the original message. - In the third step, the client sends an
ACK
message back to the server to ensure that our data is being delivered reliably.
- The client initiates the active open by sending a
-
We now have a completed three-way handshake and an established connection where both the client and server have received acknowledgment of the connection from the other party.
- The request is made up of a "request line", request header, and a body.
- Once the HTTP request is sent, it follows a similar routing procedure.
- Once the server receives the request, processes it, and finds the resource being requested, it generates an HTTP response.
- Once the response is generated, the server responds to the request. At the TCP layer.
- Once the response has been fully delivered, the client sends a FIN packet at the TCP level, to which the server responds with an ACK, and then generally sends a FIN of its own, which the client responds to with its own ACK signal.
- Browser begins processing what it has received.
An HTTP
request. An HttpRequest instance is built through an HttpRequest builder. An HttpRequest builder is obtained from one of the newBuilder methods. A request's URI , headers, and body can be set. Request bodies are provided through a BodyPublisher supplied to one of the POST
, PUT
or method methods.
Note that starting with JDK 11, Java provides a new API for performing HTTP requests, which is meant as a replacement for the HttpUrlConnection, the HttpClient API.