How can I send a file's contents as a POST parameter using cURL? How can I send a file's contents as a POST parameter using cURL? curl curl

How can I send a file's contents as a POST parameter using cURL?


You can by doing something like:

$ curl --data "foo:$(cat foo.txt)" http://localhost/yourfile.php

Note that you'll probably want to encode the file, as cacheguard said. To encode it in base64, just modify the previous command like this:

$ curl --data "foo:$(cat foo.txt | base64)" http://localhost/yourfile.php


You should encode/decode the content of your file (for instance by using the base64 command under Linux).

file foo.txt:

8<----------------------------Hello WorldI am a Secure Web Gateway8<----------------------------
base64 foo.txt | base64 -d