Form Encoding
Lesson 34 of 47 in Coddy's Networking with the Terminal course.
When you use -d, curl adds a header describing the body's format:
Content-Type: application/x-www-form-urlencodedThat long name is the format HTML forms have always used: key=value pairs joined by &. The server reads that header and knows to split the body on those characters.
Which raises the obvious question: what if a value contains an & or an =? It has to be escaped, written as a percent sign and two hex digits. A space becomes %20 or +, an ampersand becomes %26.
--data-urlencode does that escaping for you, and you should prefer it for anything a human typed. Sending raw user input through plain -d is how fields mysteriously truncate at the first ampersand.
Challenge
HardConfirm the header curl chooses for you.
- Start the capture listener on port 9124
- POST
a=1with-d - Print the Content-Type line from
req.txt
Expected output:
Content-Type: application/x-www-form-urlencodedMatch case insensitively and anchor to the start of the line.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Networking with the Terminal
4Is It Reachable?
ICMP and pingReading Ping OutputWhen Ping LiesRefused or Timed OutRecap: Reachability7Sending Data
POST with -dWhat -d Actually SendsForm EncodingSending JSONPUT and DELETERecap: Writing DataPractice on your own: Terminal playground