Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Software Engineering Tutorial
  • Software Development Life Cycle
  • Waterfall Model
  • Software Requirements
  • Software Measurement and Metrics
  • Software Design Process
  • System configuration management
  • Software Maintenance
  • Software Development Tutorial
  • Software Testing Tutorial
  • Product Management Tutorial
  • Project Management Tutorial
  • Agile Methodology
  • Selenium Basics
Open In App
Next Article:
WebSockets Protocol and Long Polling
Next article icon

Construct a simple HTTP request on TCP protocol

Last Updated : 01 Feb, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

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.


Next Article
WebSockets Protocol and Long Polling

G

geeksforgeeks user
Improve
Article Tags :
  • Project
  • Internship
  • Computer Networks
  • Software Engineering
  • Experiences
  • HTTP

Similar Reads

  • HTTP Non-Persistent & Persistent Connection | Set 1
    The Hypertext Transfer Protocol (HTTP) is an application-level protocol that uses TCP as an underlying transport and typically runs on port 80. HTTP is a stateless protocol i.e. server maintains no information about past client requests. HTTP ConnectionsNon-PersistentPersistentBasic Pre-RequisiteThe
    3 min read
  • WebSockets Protocol and Long Polling
    As one facet of net development, real-time access Among consumers and servers has now become an important step in creating interactive web programs as well as mouth-watering. Request-reaction mechanisms, even flexible and powerful as they are, may not be suitable for circumstances that call for rapi
    10 min read
  • Types of Network Protocols and Their Uses
    Network protocols are a set of rules that are responsible for the communication of data between various devices in the network. These protocols define guidelines and conventions for transmitting and receiving data, ensuring efficient and reliable data communication. What is Network Protocol?A networ
    9 min read
  • Session Initiation Protocol
    Session Initiation Protocol was designed by IETF and is described in RFC 3261. It's the protocol of application layer that describes the way to found out Internet telephone calls, video conferences and other multimedia connections, manage them and terminate them. It's one module. it's ready to estab
    2 min read
  • Why is TCP Called a Connection Oriented Protocol?
    TCP is a standard connection-oriented protocol that works under the following conditions before any transmission takes place between both devices: Establish a logical connection with the device on receiver's end The Transmission Control Protocol (TCP) is a protocol of the transport layer, which is t
    4 min read
  • 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
  • State the core components of an HTTP response ?
    Have you ever thought about how the front-end of an application communicates with the backend to get data or perform certain operations? It is done through API Requests. API stands for Application Programming Interface. The communication between our client and the API is achieved using HTTP Request
    4 min read
  • Difference Between TCP, UDP and SCTP Protocols
    In the realm of computer networking, different protocols play a vital role in facilitating the transmission of data across the internet. Three prominent protocols, TCP (Transmission Control Protocol), UDP (User Datagram Protocol), and SCTP (Stream Control Transmission Protocol), serve as the buildin
    6 min read
  • HTTP Full Form - Hypertext Transfer Protocol
    HTTP is the primary method through which web browsers and servers communicate to share information on the internet. It was invented by Tim Berners-Lee. HyperText refers to text that is specially coded using a standard coding language called HyperText Markup Language (HTML). HTTP/2 is the updated ver
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences