0

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?

2 Answers 2

2

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 
Sign up to request clarification or add additional context in comments.

2 Comments

The link in this answer is broken.
1

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.