Proxy Community
[b]"Need a simple curl post example – how do I send data with curl?"[/b] or [b]"Can someone share a basic curl pos - 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: [b]"Need a simple curl post example – how do I send data with curl?"[/b] or [b]"Can someone share a basic curl pos (/thread-b-need-a-simple-curl-post-example-%E2%80%93-how-do-i-send-data-with-curl-b-%0A%0Aor-%0A%0A-b-can-someone-share-a-basic-curl-pos--7207)

Pages: 1 2


[b]"Need a simple curl post example – how do I send data with curl?"[/b] or [b]"Can someone share a basic curl pos - shadowXchangeX - 20-11-2024

"Need a simple curl post example – how do I send data with curl?"

Hey folks,

I'm kinda stuck here. Trying to send some data via curl, but every time I mess up the syntax.

Can someone share a basic curl post example? Like, just a simple one with JSON data?

I tried `curl -X POST https://example.com/api` but it’s not working, and I’m not sure where to put the JSON payload.

A quick working snippet would save me hours of googling lol.

Thanks in advance!

---

*or*

"Struggling with curl post example – any quick working snippet?"

Yo,

Total noob here. Need a curl post example to hit an API endpoint.

Something like sending `{"name": "test"}` to a URL.

I keep getting 400 errors... am I missing headers?

Pls help a fellow dev out with a quick example!

Cheers.


“” - DeepWebWalker - 13-01-2025

Here's a quick curl post example for ya:

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

You gotta include the `-H` flag for headers (JSON needs it) and `-d` for the data.

If you're still getting 400s, check if the endpoint needs auth—maybe add `-H "Authorization: Bearer YOUR_TOKEN"`.


“” - StealthRouteX - 12-02-2025

Yo, had the same issue last week!

For a simple curl post example, this works:

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

Pro tip: Use https://reqbin.com/ to test your requests before running curl. Saves a ton of time!

Also, 400 usually means bad data or missing headers. Double-check your JSON formatting.


“” - IPSwap88 - 25-03-2025

Hey! Here’s a basic curl post example with JSON:

```
curl -X POST https://example.com/api \
--header "Content-Type: application/json" \
--data '{"username":"foo","password":"bar"}'
```

If it’s still failing, try `-v` to see verbose output—helps debug the issue.

Also, Postman (https://www.postman.com/) is great for testing APIs before writing curl commands.


“” - vpnDiver99 - 01-04-2025

Dude, you’re missing the headers! Here’s how I do it:

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

Sometimes APIs are picky about `Accept` headers too.

If you’re on Windows, watch out for quotes—use double quotes outside and escape the JSON ones.


“” - sekiroXpert - 03-04-2025

Here’s a foolproof curl post example:

```
curl -X POST https://example.com/api \
-H 'Content-Type: application/json' \
-d '{"field1":"value1", "field2":"value2"}'
```

Bonus: Use `jq` to prettify JSON responses like this:

```
curl ... | jq
```

If you’re stuck, paste your error—we’ll figure it out!


“” - shadowXchangeX - 04-04-2025

Wow, thanks everyone! Didn’t realize the headers were that important.

Tried the first curl post example and it worked!

But now I’m getting a 401—guess I need auth. How do I add a basic auth token?

Also, jq looks dope, gonna try that next.

Cheers!


“” - shadowLeap99 - 06-04-2025

400 errors? Classic.

Try this curl post example:

```
curl -X POST https://example.com/api \
-H "Content-Type: application/json" \
-d @data.json
```

Put your JSON in a file (`data.json`) to avoid quote issues.

Also, check if the API docs mention required fields—sometimes it’s not the syntax but missing data.


“” - phantomCircuitX - 08-04-2025

For a dead-simple curl post example:

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

If it’s still not working, maybe the endpoint’s picky. Try `-v` to see the full request/response.

Oh, and https://httpie.io/ is a nicer alternative to curl for quick testing.