How to properly send a curl post request with JSON data? or Why is my curl post request returning a 4

14 Replies, 1534 Views

Pro tip: Some APIs reject curl post requests if the `-d` data isn’t formatted *just* right. Try wrapping your JSON in single quotes and escaping double quotes inside:

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

Or use `--data-binary` instead of `-d` to preserve formatting. Also, check if the API expects URL-encoded data instead of raw JSON.

Messages In This Thread



Users browsing this thread: 1 Guest(s)