POST with -d
Lesson 32 of 47 in Coddy's Networking with the Terminal course.
So far every request has asked for something. -d sends something instead:
curl -s -d 'name=ada' http://127.0.0.1:9122/signupTwo things happen the moment you add it. curl switches the method from GET to POST without being asked, and it attaches what you gave it as the request body.
So -d is not just "add data", it changes the kind of request. If you want a POST with no body at all you have to say -X POST yourself.
Where GET puts its parameters in the URL for everyone to see and log, POST puts them in the body. That is why forms with passwords use POST: not because the body is encrypted, it is not, but because URLs end up in browser history, server logs and referrer headers.
Challenge
ExpertSend your first POST and read back what the server received.
- Start the capture listener on port 9122 (it replies 200 and writes the request into
req.txt) - POST
name=adatohttp://127.0.0.1:9122/signup - Print the first line of
req.txt
Expected output:
POST /signup HTTP/1.1Give curl
--max-time 3so it does not wait forever, and discard its output.
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