"What’s the Correct Way to POST JSON with cURL?"
Hey folks,
I keep messing up when trying to post json curl requests. Like, I *think* I’m doing it right, but the server keeps yelling at me.
Here’s what I’m doing:
```bash
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://example.com/api
```
But sometimes it just... doesn’t work? Am I missing something obvious?
Also, do I *really* need the `-X POST`? Feels redundant, but I see it everywhere. And what if my json has quotes inside? Do I need to escape them?
Pls halp, my sanity is slipping. 🙃
(Also, if you’ve got a better one-liner to post json curl, drop it below!)
Hey folks,
I keep messing up when trying to post json curl requests. Like, I *think* I’m doing it right, but the server keeps yelling at me.
Here’s what I’m doing:
```bash
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://example.com/api
```
But sometimes it just... doesn’t work? Am I missing something obvious?
Also, do I *really* need the `-X POST`? Feels redundant, but I see it everywhere. And what if my json has quotes inside? Do I need to escape them?
Pls halp, my sanity is slipping. 🙃
(Also, if you’ve got a better one-liner to post json curl, drop it below!)
