Menu
Coddy logo textTech

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-urlencoded

That 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 icon

Challenge

Hard

Confirm the header curl chooses for you.

  1. Start the capture listener on port 9124
  2. POST a=1 with -d
  3. Print the Content-Type line from req.txt

Expected output:

Content-Type: application/x-www-form-urlencoded

Match case insensitively and anchor to the start of the line.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Networking with the Terminal

Practice on your own: Terminal playground