How to curl post a URL with proper syntax and headers? or What’s the correct way to curl post a URL?

14 Replies, 809 Views

Bro, I feel you. Curl post a url can be a pain at first.

Headers are *everything*. At minimum, you need `Content-Type`. Some APIs also want `Accept: application/json`.

Here’s a foolproof template:

```
curl -X POST https://example.com/api \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"key":"value"}'
```

If it still fails, use `-v` to see the full request/response. Lifesaver for debugging.

Messages In This Thread



Users browsing this thread: 1 Guest(s)