WRRC and Java
High-level HTTP
Local Processing
- Your computer deciphers your URL, and adds (in the background) the rest of the necessary details to send out a request
- It checks its local cache to see if it can find the request there, and put less burden on the system elsewhere. If it cannot…
- It sends out a Domain Name Server (DNS) request.
- Once it finds it (or not, and so ends this process) it connects to the DNS via a transport layer protocol via a TCP connection, and communication can now occur.
- Now: the http request of the URL goes to the DNS to resolve it.
- The communication is ongoing so long as there is a connection.
- Upon all completion (and a brief timeout) the communication shuts down, and both sides clean up various details, and both are ready to make additional calls / requests.
Java HTTP Request example
Note: below attribution for quotes and code blocks at this page.
-
HttpUrlConnection - the Java 8 class “to perform basic HTTP requests without the use of any additional libraries”. This is found within the java.net package.
-
Creating a Request - done so by using openConnection() and the requestMedho attribute is where the GET / PUT / POST / DELETE (and TRACE) is put.
-
Adding Request Parameters - the best way to have this, is the example, screenshot from here.

-
Setting Request Headers - done by using setRequestProperty(). Headers are read by getHeaderField().
-
Configuring Timeouts - setConnectTimeout() and setReadTimeout() methods. They both take in milliseconds as args.
-
Handling Cookies - packages CookieManager and HttpCookie add in managing cookies.
-
Handling Redirects - use setInstanceFollowRedirects().
-
Reading the Response = first parse a response using “InputStream of the of the HttpUrlConnection instance”, then execute with getResponseCode(), connect(), getInputStream(), or getOutputStream().
-
Reading Response on Failed Requests - you’ll need to “else {}” the stream from HttpUrlConnection.getErrorStream().
-
Building the Full Response - you return your response string first by building the string, then sending it with “some of the methods” (doesn’t go into further detail) from the HttpUrlConnection instance.