Upperstage
Upperstage

Reputation: 3757

Upload file contents using cURL

I have a script with which I POST data to a server using cURL. When I use an HTML form to POST the same data, the POST looks something like this and all is well:

description=Something&name=aName&xml=wholeBiunchOfData&xslt=moreData

The XML and XSLT are large and change; I would prefer to maintain them in external files. However, the following does not work as I expect;

curl --cookie cjar --cookie-jar cjar --location --output NUL ^
 --data "name=aName&description=Something" ^
    --data "[email protected]" ^
 --data "[email protected]" ^
 http://someUrl.html

I have tried various combinations of the @ and local files without success. How do I POST the contents of a file?

Upvotes: 0

Views: 2443

Answers (2)

stimms
stimms

Reputation: 44054

Looking at the man page it looks like the --data @file syntax does not permit for a variable name, it must be in the file. http://paulstimesink.com/2005/06/29/http-post-with-curl/. You could also try using a backtick

curl --cookie cjar --cookie-jar cjar --location --output NUL ^
 --data "name=aName&description=Something" ^
 --data "xml=`cat localFile.xml`" ^
 --data "xslt=`cat someFile.xml`" ^
 http://someUrl.html

Upvotes: 2

mlschechter
mlschechter

Reputation: 994

I'd recommend trying the following:

curl --cookie cjar --cookie-jar cjar --location --output NUL ^
 --data "name=aName&description=Something" ^
    --data-urlencode "[email protected]" ^
 --data-urlencode "[email protected]" ^
 http://someUrl.html

XML (including stylesheets) will need to be URL-encoded before being made part of a URL.

You can also use --trace-ascii - as an additional parameter to dump the input and output to standard out for further debugging, and you can find more information on the main man page.

Hope this helps!

Upvotes: 1

Related Questions