Send JSON Data as Payload using cURL HTTP POST Request


In order to send JSON data as payload with an HTTP Post cURL request you need to add,


1. The JSON Header for Content-type

-H "Content-Type: application/json"

2. Include the JSON data payload using --data flag

--data '{"city":"USA","state":"New York"}' 

Complete Example

curl -X POST \
-H "Content-Type: application/json" \
--data '{"city":"USA","state":"New York"}' \
http://example.com/api/endpoint
cURL with HTTP POST JSON Data Payload Example

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap