Proxy Community
Need a simple curl POST example – can anyone share a quick snippet? or Struggling with a curl POST example – any - Printable Version

+- Proxy Community (https://proxycommunity.com/forum)
+-- Forum: Technical Community Support (https://proxycommunity.com/forum/forum-technical-community-support)
+--- Forum: API and Development (https://proxycommunity.com/forum/forum-api-and-development)
+--- Thread: Need a simple curl POST example – can anyone share a quick snippet? or Struggling with a curl POST example – any (/thread-need-a-simple-curl-post-example-%E2%80%93-can-anyone-share-a-quick-snippet-or-struggling-with-a-curl-post-example-%E2%80%93-any)

Pages: 1 2 3


Need a simple curl POST example – can anyone share a quick snippet? or Struggling with a curl POST example – any - vpnDash_99 - 03-04-2024

"Hey folks,

Struggling to get a curl POST example working for an API test. Every time I try, I either get a 400 error or the server just ignores my data.

Can someone share a quick snippet for a basic curl POST example with JSON data? Like, the simplest one possible—just need to send `{"name": "test"}` to `https://example.com/api`.

I’ve tried a bunch of flags, but maybe I’m missing something obvious.

Also, how do you usually format the headers? Do you always need `-H 'Content-Type: application/json'`?

Thanks in advance!

(PS: If you’ve got a better curl POST example for beginners, I’m all ears.)"


“” - shadowPioneer99 - 04-07-2024

Here’s your first reply:


“” - deepJump99 - 02-09-2024

Hey! Here’s a dead-simple curl POST example for your case:

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

The `-X POST` is optional (curl defaults to POST with `-d`), but I like being explicit.

And yes, you *usually* need the `Content-Type` header—some APIs will ignore your data without it.

If you’re still stuck, try `-v` to see the full request/response. Helps debug those 400 errors!


“” - webLurker77 - 10-02-2025

400 errors are the worst. Here’s what works for me 99% of the time:

```
curl -H "Content-Type: application/json" -d '{"name":"test"}' https://example.com/api
```

Pro tip: If the API needs auth, slap on `-H 'Authorization: Bearer YOUR_TOKEN'`.

Also, check out Postman or Insomnia if you’re tired of debugging curl commands. They’re lifesavers for API testing.


“” - HyperMancer77 - 15-03-2025

Yo, had the same issue last week! Here’s the magic combo:

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

If it’s still failing, maybe the API expects a trailing slash or something? Try `https://example.com/api/`.

Also, `jq` is handy for pretty-printing JSON responses if you’re on Linux/Mac.


“” - vpnDash_99 - 16-03-2025

Thanks everyone! The `-v` flag was a game-changer—turns out the API was rejecting my request because I forgot the trailing slash.

This worked:

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

Still weird that the server cares about the slash, but hey, it’s working now.

Quick Q: How do I handle nested JSON? Like `{"user": {"name": "test"}}`? Same format?


“” - deepShifter77 - 23-03-2025

For a beginner-friendly curl POST example, this should work:

```
curl -d '{"name":"test"}' -H "Content-Type: application/json" -X POST https://example.com/api
```

Headers *matter*—some APIs freak out if you skip `Content-Type`.

If you’re on Windows, watch out for quote issues. Sometimes swapping `'` for `"` around the JSON fixes it.


“” - shadowDart77 - 26-03-2025

Struggling with curl POST too? Here’s the bare minimum:

```
curl -d '{"name":"test"}' -H "Content-Type: application/json" https://example.com/api
```

Fun fact: `-X POST` isn’t needed if you use `-d`.

If you’re getting ignored, try `-v` to see if the request even leaves your machine.


“” - darkRushX77 - 26-03-2025

Here’s my go-to curl POST example for APIs:

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

Bonus: If the API uses HTTPS and you’re getting cert errors, add `-k` (but only for testing—don’t ship that!).


“” - RouterHider - 28-03-2025

Short and sweet:

```
curl -X POST https://example.com/api -H "Content-Type: application/json" -d '{"name":"test"}'
```

If 400 persists, maybe the server expects `Accept: application/json` too? Some APIs are picky.