Construct a simple HTTP request on TCP protocol
Last Updated :
01 Feb, 2022
HTTP Request :
- HTTP messages are how data is exchanged between a server and a client. In this, there are two types of messages where one is HTTP client request and the second is the response from the server.
- Messages in textual form and it is encoded in ASCII form, and span over multiple lines. And messages were openly sent across the connection in the case of HTTP/1.1 and earlier versions of the protocol. In HTTP/2, the once human-readable message is now divided up into HTTP frames, providing optimization and performance improvements.
- Let’s now see the components of an HTTP request & response by actually creating one. The telnet client helps us connect to other computers on the internet. The format is telnet, hostname, and port.

Note -
You can also use this online telnet client.
Opening a TCP connection to server via telnet
Steps to Construct a simple HTTP request on TCP protocol :
Step-1 :
The default port for HTTP is 80 and the telnet command has us connected to the HTTP port on the geeksforgeeks.org server. We can start sending HTTP requests to the server now.
Step-2 :
How do we create an HTTP request? Let’s check the HTTP protocol definition doc here to get an idea of how to frame an HTTP request.
Request :
A request message from a client to server includes, within the
first line of that message, the method to be applied to the resource,
the identifier of the resource, and the protocol version in use.
Request = Request-Line
*(( general-header
| request-header
| entity-header ) CRLF )
CRLF
[ message-body ]
Request-Line :
The Request-Line begins with a method token, followed by the
Request-URL and the protocol version, and ending the CRLF.The
elements are separated by SP characters. No CR or LF is allowed
except in the final CRLF sequence.
Request-Line = Method SP Request-URI SP HTTP_Version CRLF
HTTP Request specification :
Below given is the screenshot for your reference that shows the HTTP request specification.

HTTP Request-Response components :
- From the above figure, different parts of the HTTP communication are:
- Request Line (HTTP Request)
- Status Line & Response Header (HTTP Response)
- Response Body (HTTP Response)
- Try to figure out what some of these response headers mean & what their uses are - for starters, see Last-Modified, Content-Length, Content-Type
- If we analyze the network packets transferred to/from our computer during the above communication, we’ll be able to understand some things (192.168.43.197 is the client computer & 192.241.136.170, the server)
- The client initiates a TCP connection request to the server (Line 1) - this is performed when we execute the telnet command
- HTTP's communication happens using this established TCP connection (see the bottom part that lists outs the protocols used for the resource transfer)
- The client sends the HTTP Request line to the server (Line 6) to which the server responds with the HTTP Status code & data as we saw earlier in the telnet output
Note -
We can also analyze Network packets using Wire shark this will be done by you.
Similar Reads
Application Layer Protocols in TCP/IP TCP/IP stands for Transport Control Protocol/Internet Protocol. TCP/IP suite is considered as a basis on which a virtual network exists. TCP/IP makes use of client-server model for communication where service is provided by the server to the client or other systems. TCP/IP protocol consists of four
7 min read
What is TCP (Transmission Control Protocol)? Transmission Control Protocol (TCP) is a connection-oriented protocol for communications that helps in the exchange of messages between different devices over a network. It is one of the main protocols of the TCP/IP suite. In OSI model, it operates at the transport layer(Layer 4). It lies between th
5 min read
TCP Connection Establishment TCP (Transmission Control Protocol) is a core internet protocol that ensures reliable, ordered, and error-checked delivery of data between computers. It establishes a connection using a three-way handshake before data transfer begins, allowing both devices to synchronize and agree on communication p
4 min read
TCP Connection Establishment TCP (Transmission Control Protocol) is a core internet protocol that ensures reliable, ordered, and error-checked delivery of data between computers. It establishes a connection using a three-way handshake before data transfer begins, allowing both devices to synchronize and agree on communication p
4 min read
Difference between MQTT and HTTP protocols 1. Message Queuing Telemetry Transport (MQTT) : It was created by Andy Standford-Clark and Arlen Nipper. It is an IoT interaction protocol based on the Publish/Subscribe model. This model is a simple model that provides support for QoS (Quality of Service). Due to its abilities, it can be found in e
2 min read
Difference between AMQP and HTTP Protocols AMQP (Advanced Message Queuing Protocol) and HTTP (Hypertext Transfer Protocol) are two communication protocols used in distributed systems, however, they perform different functions and have different properties. In this article, we are going to discuss the differences between AMQP and HTTP protoco
4 min read