Posting JSON via curl

I learnt following lesson while trying to submit a job using livy  API which was part of azure HDInsight cluster.

By default when you use following command.


curl  -k --user "admin:<password> " -v  -d  '{"name":"gopal", "address":"1512 edwina ct" }'   https://<clustername>.azurehdinsight.net/livy/batches -H  "X-Requested-By: admin"

It will treat the payload as application/x-www-form-urlencoded. So you need to specify Content-Type header.


curl  -k --user "admin:<password> " -v -H "Content-Type: application/json" 
 -d  '{"name":"gopal", "address":"1512 edwina ct" }'   https://<clustername>.azurehdinsight.net/livy/batches -H  "X-Requested-By: admin"

This may work fine on linux but on window even this is going to be an issue. So you need put json payload into a file. Let us call the file "payload.json" which has following content.

{"name":"gopal", "address":"1512 edwina ct" }

Then invoke the curl in following manner.

curl  -k --user "admin:<password> " -v -H "Content-Type: application/json" 
 -d  @payload.json   https://<clustername>.azurehdinsight.net/livy/batches -H  "X-Requested-By: admin"

Comments

Popular posts from this blog

SQL

Analytics

DBeaver