Forms
Submitting forms is very similar to sending JSON requests. Often the onlydifference is in adding the —form, -f
option, which ensures thatdata fields are serialized as, and Content-Type
is set to,application/x-www-form-urlencoded; charset=utf-8
. It is possible to makeform data the implicit content type instead of JSONvia the config file.
Regular forms
- $ http --form POST api.example.org/person/1 name='John Smith'
- POST /person/1 HTTP/1.1
- Content-Type: application/x-www-form-urlencoded; charset=utf-8
- name=John+Smith
File upload forms
If one or more file fields is present, the serialization and content type ismultipart/form-data
:
- $ http -f POST example.com/jobs name='John Smith' [email protected]~/Documents/cv.pdf
The request above is the same as if the following HTML form weresubmitted:
- <form enctype="multipart/form-data" method="post" action="http://example.com/jobs">
- <input type="text" name="name" />
- <input type="file" name="cv" />
- </form>
Note that @
is used to simulate a file upload form field, whereas[email protected]
just embeds the file content as a regular text field value.