Monday, February 12, 2024

How to Execute a POST Request with JSON Payload with cURL

  • ทดสอบใช้ CURL บน linux Ubuntu 22.04 เพื่อทดสอบ Restfull api

Pattern

curl -X POST [URL] -H "Content-Type: application/json" -d [JSON_PAYLOAD]

Ex

curl -X POST http://example.com/api/data -H "Content-Type: application/json" -d '{"name": "John Doe", "age": 25}'

curl -X POST http://example.com/api/data -H "Content-Type: application/json" -d @data.json
Ref

  • https://tecadmin.net/post-json-data-with-curl-command/
  • https://www.linode.com/docs/guides/curl-for-rest-api/

No comments:

Post a Comment