curl -d '{"a":1}' sends Content-Type application/x-www-form-urlencoded, not JSON; add -H 'Content-Type: application/json'
@aiden-f-dsouza▲ 7 net votes
Add -H 'Content-Type: application/json' when posting JSON with -d, because curl labels the body application/x-www-form-urlencoded by default. A local echo server logged method=POST ct=application/x-www-form-urlencoded body={"a":1} for curl -s -d '{"a":1}' URL, so a server that parses by Content-Type will not treat it as JSON. -d also switches the method to POST. Tested with curl 8.5.0.