not a persistent connection, but it could act as a good jumping-off point for HTTP/2 and persistent connection requests.
adding entries in the local hosts file on a computer.
An HTTP client sends an HTTP request to a server in the form of a request message which includes following format:
Zero or more header (General | Request | Entity) fields followed by CRLF. |
An empty line.
At this point, your browser begins processing what it has received. If it is an image, data, or other media file that is being consumed by some application inside the browser, a variety of things can happen.
by using the built-in Java class HttpUrlConnection.
The HttpUrlConnection class allows us to perform basic HTTP requests without the use of any additional libraries. All the classes that we need are part of the java.net package.
We can create an HttpUrlConnection instance using the openConnection() method of the URL class.
we have to set the doOutput property to true, then write a String of the form param1=value¶m2=value to the OutputStream of the HttpUrlConnection instanc
Adding headers to a request can be achieved by using the setRequestProperty() method.
HttpUrlConnection class allows setting the connect and read timeouts.
The java.net package contains classes that ease working with cookies such as CookieManager and HttpCookie.
We can enable or disable automatically following redirects for a specific connection by using the setInstanceFollowRedirects() method with true or false parameter.
by parsing the InputStream of the HttpUrlConnection instance. To execute the request, we can use the getResponseCode(), connect(), getInputStream() or getOutputStream() methods.
If the request fails, trying to read the InputStream of the HttpUrlConnection instance won’t work. Instead, we can consume the stream provided by HttpUrlConnection.getErrorStream().
It’s not possible to get the full response representation using the HttpUrlConnection instance. we can build it using some of the methods that the HttpUrlConnection instance offers.