Here is a summary of what I learned from these articles:
- browser extracts the "scheme"/protocol (HTTP)
- host (www.example.com)
- optional port number 8080
- resource path
- query strings
|http|://|www.example.com||:5000||/mainpage||?query=param&query2=param2|
- browser need to resolve an IP address by:
- look through its own cache of recently requested URLs
- the operating system’s cache of recent queries
- your router’s cache
- your DNS cache
-
Like the processing done locally, resolving an IP from a "DNS server"2 is a sequence that includes many steps, and includes failovers if the first request fails to return an address.
-
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 the DNS server you have targeted cannot locate the given hostname, it passes the request along to another DNS server.If an address for the given domain cannot be resolved, the server responds with a failure and your browser returns an error.
-
the requesting client now has a target IP
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 :
- TCP connections are opened using what’s known as a three-way handshake, the server must already be "listening" on a portable
now that the client has an IP address and a TCP connection, it can finally send an HTTP request.
- now the response has been fully delivered
- At this point, your browser begins processing what it has received.
- The
HttpUrlConnectionclass allows us to perform basic HTTP requests without the use of any additional libraries. (part of the java.net package) - We can create an HttpUrlConnection instance using the
openConnection()method of the URL class (create but doesn't establish the connection yet) - The HttpUrlConnection class is used for all types of requests by setting the requestMethod attribute to one of the values: GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE.
URL url = new URL("http://example.com");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");-
If we want to add parameters to a request, we have to set the doOutput property to true, then write a String of the form param1=value¶m2=value to the OutputStream
-
Adding headers to a request can be achieved by using the
setRequestProperty()method:con.setRequestProperty("Content-Type", "application/json"); -
HttpUrlConnectionclass allows setting the connect and read timeouts. These values define the interval of time to wait for the connection to the server to be established or data to be available for reading -
To set the timeout values, we can use the setConnectTimeout() and setReadTimeout() methods:
con.setConnectTimeout(5000);
con.setReadTimeout(5000);-
The java.net package contains classes that ease working with cookies such as
CookieManagerandHttpCookie. -
We can enable or disable automatically following redirects for a specific connection by using the
setInstanceFollowRedirects()method with true or false parameter -
Reading the response of the request can be done by parsing the InputStream of the
HttpUrlConnectioninstance -
To execute the request, we can use the
getResponseCode(),connect(),getInputStream()orgetOutputStream() -
if the request fails we can consume the stream provided by
HttpUrlConnection.getErrorStream(). -
then we can build the Full Response.