d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

HTTP Protocol: Obviously Unobvious – DZone Web Dev

Hyper Text Transfer Protocol

HTTP protocol nowadays is still one of the most popular protocols used over the internet. But many developers still can’t explain clearly what is it. In this article, you will find out what HTTP is practically is. 

Protocol Meaning

But stepping back a little let’s remind what is the meaning of Protocol. A protocol can be understood as a contract or agreement between sender and receiver. The HTTP protocol is described in RFC 2616. The main purpose of the HTTP protocol is to send web data to browsers to render it. 

Structure of HTTP Protocol

As many of you know HTTP protocol arrange communication between web browser and server. So protocol structure includes:

  • URL or Uniform Resource Locator.
    For example: http://www.google.com 
  • Method Name.
    For example: GET or PUT, there are more exotic: HEAD, OPTIONS
  • Request headers.
    For example: Keep-Alive: timeout=5, max=1000
  • Request body.
    For example: body in json format : “‘id’:’12′”

HTTP Is Application Layer Live on Top of Reliable Protocol

The HTTP protocol can be implemented on top of any protocol exception one condition – such protocol has to be reliable. For example, TCP protocol has delivery acknowledgment but UDP doesn’t. Theoretically, you still can create a UDP HTTP server but in that case, you won’t follow RFC 2616 requirements, and such a solution can be named HTTP. So if we portray HTTP as a layer it will looks like this:

Let’s See What’s Under the Hood

Receiving HTTP Requests Using TCP Java Server

In order to practically see what we receive from regular HTTP requests we install simple Java server and check the body of received request.

Preparing HTTP Request Using Postman Plugin

Before creating the server we prepare an HTTP request using Postman plugin.

Preparing an HTTP Request

Writing Simple TCP Java Server

Let’s use a simple Java TCP server provided by JDK. It will just listen to port 8080 and print all lines received from that port: 

Once the server is started, we send a request from Postman and check output in the console:

Output from Console

So here magic disappears. And you can see that the TCP server received just a regular string that follows HTTP protocol and provides headers/URL/method/body.

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this