Fundamentals 10 min read

Understanding GET vs POST: HTTP Request Methods Explained with Real Examples

This article explains the fundamentals of HTTP GET and POST request methods, detailing their request line, headers, and body structures, illustrating each with real‑world examples and code snippets, and clarifying their safety, idempotence, caching, and practical differences.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Understanding GET vs POST: HTTP Request Methods Explained with Real Examples

Overview

The article summarizes the eight HTTP request methods, focusing on GET and POST, and outlines the structure of an HTTP request message.

HTTP Request Message Structure

An HTTP request consists of three parts:

Request line : method, URL, and HTTP version (e.g., GET /path?query HTTP/1.1).

Headers : zero or more header fields, each as Header-Name: value, terminated by CRLF.

Body (request data) : present for methods like POST; absent for GET.

Example of a GET request to GitHub’s API:

GET /search/users?q=JakeWharton HTTP/1.1
Host: api.github.com
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: _octo=...; _ga=...; logged_in=yes; dotcom_user=GoMarck; _gid=...; _gat=1

The request line shows the GET method, the URL /search/users?q=JakeWharton, and HTTP/1.1. All subsequent lines are headers; there is no body.

Example of a POST request:

POST / HTTP/1.1
Host: www.wrox.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 40
Connection: Keep-Alive

name=Professional%20Ajax&publisher=Wiley

Here the method is POST, the request body contains form data ( name=Professional%20Ajax&publisher=Wiley), separated from the headers by a blank line.

Characteristics of GET

Parameters are appended to the URL after a ? and separated by &.

Designed for safe, idempotent data retrieval; it should not modify server state.

Browsers may cache GET responses, reducing network traffic.

URL length is limited by browsers and servers, not by the HTTP spec.

Typically sends a single TCP packet containing both headers and (empty) body.

Characteristics of POST

Used to submit data that may change server resources (e.g., form submissions, likes).

Not considered safe or idempotent because it can modify state.

Request data resides in the body, allowing virtually unlimited size.

Usually involves two TCP packets: one for headers, another for the body after a 100 Continue response.

GET vs POST Differences

Although both are HTTP methods built on TCP, the protocol distinguishes them to simplify management: GET for retrieving resources, POST for creating or updating resources. Their practical differences arise from where parameters are placed (URL vs body), caching behavior, and compliance with safety and idempotence rules. While technically you could swap parameter locations, servers may or may not honor such non‑standard usage.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

HTTPprotocolrequest methodsgetPOSTweb fundamentals
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.