By adding --trace-ascii output-file.txt
in your curl command line, the body of the message that curl sends to server is recorded in output-file.txt
. You can also use --trace-ascii -
to send the output to your terminal standard output.
What you need to specify in the header are:
- the
Content-Type
asmultipart/form-data; boundary=RANDOM-BOUNDARY
whereRANDOM-BOUNDARY
is a line separator that must not exist in the form data and as any line of the posted files. - the
Content-Length
as the total length in bytes of the message without header, including all the separators.
In the body each line is also separated by \r\n
, the first and the last line must have RANDOM-BOUNDARY
For each form field (e.g. -F f2=arg2) you must have a part as:
Content-Disposition: form-data; name="f2"
arg2
and for file contents you must use:
Content-Disposition: form-data; name="f1"; filename="file"
Content-Type: text/plain
Contents of file
Each part must be separated by RANDOM-BOUNDARY
.
See also: How do I post a file to a website?