tags:

views:

28

answers:

2

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?

+1  A: 

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://www.paulstimesink.com/post/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
stimms
Thanks for the answer.
Upper Stage
+1  A: 

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!

mlschechter
Fantastic! Many thanks!
Upper Stage