How to POST URL in data of a curl request

Vivek Muthal picture Vivek Muthal · Aug 13, 2013 · Viewed 104.7k times · Source

I am trying to post two parameters using curl, path and fileName:

curl --request POST 'http://localhost/Service' --data "path='/xyz/pqr/test/'&fileName='1.doc'"

I know something is wrong in this. I have to use something like URLEncode. I tried many things still no luck.

Please give an example how can I post the url in data of curl request.

Answer

konsolebox picture konsolebox · Aug 13, 2013

Perhaps you don't have to include the single quotes:

curl --request POST 'http://localhost/Service' --data "path=/xyz/pqr/test/&fileName=1.doc"

Update: Reading curl's manual, you could actually separate both fields with two --data:

curl --request POST 'http://localhost/Service' --data "path=/xyz/pqr/test/" --data "fileName=1.doc"

You could also try --data-binary:

curl --request POST 'http://localhost/Service' --data-binary "path=/xyz/pqr/test/" --data-binary "fileName=1.doc"

And --data-urlencode:

curl --request POST 'http://localhost/Service' --data-urlencode "path=/xyz/pqr/test/" --data-urlencode "fileName=1.doc"