![]() |
|
How do I properly use curl --post to send data in a request? or What's the correct syntax for curl -- - 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: How do I properly use curl --post to send data in a request? or What's the correct syntax for curl -- (/thread-how-do-i-properly-use-curl-post-to-send-data-in-a-request-or-what-s-the-correct-syntax-for-curl--7651) Pages:
1
2
|
How do I properly use curl --post to send data in a request? or What's the correct syntax for curl -- - secureWalkerX - 19-01-2025 Hey folks! So I'm trying to figure out how to properly use curl --post to send some data, but I’m kinda stuck. Like, what’s the right syntax for form data? I tried something like: `curl --post "name=foo&age=25" https://example.com` But it’s not working?? Am I missing something obvious? Also, what’s the diff between curl --post and just -X POST? Seen both around and got confused. Oh, and if anyone’s got tips for sending JSON with curl --post, that’d be awesome too. My attempts keep getting rejected lol. Thanks in advance! 🙏 “” - webDiverX - 24-02-2025 Hey! You’re close, but curl --post isn’t the correct flag—it’s actually `-d` or `--data` for form data. Try this: `curl -d "name=foo&age=25" https://example.com` For JSON, use `-H "Content-Type: application/json"` and `-d '{"name":"foo","age":25}'`. And `-X POST` explicitly sets the method, while `-d` implies POST. Hope that helps! “” - SecureLinkX - 02-03-2025 lol yeah curl --post isn’t a thing, mate. You wanna use `-d` or `--data-urlencode` for form stuff. For JSON, slap on a header like `-H "Content-Type: application/json"` and then your JSON data. Also, check out Postman if you’re struggling—way easier to visualize requests. “” - VeilWalker99 - 28-03-2025 The correct syntax for form data with curl is: `curl -X POST -d "name=foo&age=25" https://example.com` For JSON: `curl -X POST -H "Content-Type: application/json" -d '{"name":"foo","age":25}' https://example.com` `-X POST` is just explicit, while `-d` defaults to POST. No such thing as curl --post, tho. “” - darkTrekker77 - 08-04-2025 Dude, curl --post doesn’t exist. You’re mixing flags. Use `-d` for data. Example for form data: `curl -d "name=foo&age=25" https://example.com` For JSON, add the content-type header: `curl -d '{"name":"foo"}' -H "Content-Type: application/json" https://example.com` Pro tip: Use `curl --help` or check the man pages. “” - secureWalkerX - 12-04-2025 Ohhh, that makes so much sense now! Thanks, everyone—didn’t realize curl --post wasn’t a thing. Tried the `-d` flag with JSON and it worked like a charm: `curl -H "Content-Type: application/json" -d '{"name":"foo"}' https://example.com` Quick follow-up: What’s the best way to handle auth headers with curl? Like, if I need to add a token? Also, shoutout to the Postman suggestion—def gonna check that out. “” - cloakJumpX - 13-04-2025 Ah, the classic curl confusion! `curl --post` isn’t valid—use `-X POST` or just `-d`. For form data: `curl -d "name=foo&age=25" https://example.com` For JSON, don’t forget the header: `curl -X POST -H "Content-Type: application/json" -d '{"name":"foo"}' https://example.com` Also, try https://reqbin.com/ to test requests before curling. “” - maskedDartX - 13-04-2025 You’re missing the `-d` flag! curl --post isn’t a real option. Form data: `curl -d "name=foo&age=25" https://example.com` JSON: `curl -X POST -H "Content-Type: application/json" -d '{"name":"foo"}' https://example.com` `-X POST` is optional here since `-d` implies POST. “” - VeilOrbit77 - 13-04-2025 Nope, no such thing as curl --post. Use `-d` or `--data` instead. For form data: `curl -d "name=foo&age=25" https://example.com` For JSON, add the header: `curl -H "Content-Type: application/json" -d '{"name":"foo"}' https://example.com` Bonus: Use `-v` to see verbose output and debug. “” - dataVoyX99 - 13-04-2025 curl --post? Nah, fam. It’s `-d` for data. Form data: `curl -d "name=foo&age=25" https://example.com` JSON: `curl -X POST -H "Content-Type: application/json" -d '{"name":"foo"}' https://example.com` `-X POST` is redundant with `-d`, but some folks like being explicit. |