What -d Actually Sends
Lesson 33 of 47 in Coddy's Networking with the Terminal course.
The request line told you the method. Now look at the body, which is the last thing in the request, after the blank line.
Whatever you passed to -d is sent literally. -d 'name=ada' puts exactly name=ada on the wire. Several -d flags are joined with &, so -d 'a=1' -d 'b=2' sends a=1&b=2.
curl also adds a Content-Length header counting those bytes, because the server needs to know where the body ends. You do not have to compute it, which is one of the quiet conveniences of using a client instead of nc.
Reading the body back off the wire is the fastest way to settle any argument about what a client is really sending.
Challenge
ExpertRead your own body back off the wire.
- Start the capture listener on port 9123
- POST the two fields
name=adaandrole=eng, as two separate-dflags - Print the last line of
req.txt, which is the body
Expected output:
name=ada&role=engTry 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