Translate a PHP cURL to a bash cURL call Translate a PHP cURL to a bash cURL call curl curl

Translate a PHP cURL to a bash cURL call


Use cURL to POST your data as JSON.

curl -i \-H "Accept: application/json" \-H "Content-Type: application/json" \-X POST --data '{"api_user": "username", "api_key":"password!"}' \--insecure \https://api.example.com/send.json

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); equals -k, --insecure.

curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData))

equals -X POST --data ...

CURLOPT_RETURNTRANSFER... hmm, i don't know ,)


-d is the curl flag to send POST data, but you'll have to format it as a JSON string:

curl -H "Content-Type: application/json" -d '{ "api_user": "username", "api_key": "password" }' https://api.example.com/send.json

And now with those extra options (look them up in the curl man page):

curl -X POST -k -H "Content-Type: application/json" -d '{ "api_user": "username", "api_key": "password" }' https://api.example.com/send.json

As a much friendlier alternative to curl I recommend checking out httpie. Here's what your call would look like with httpie:

http --verify=no https://api.example.com/send.json api_user=username api_key=password