I use HTTPie to POST a
multipart/form-data request (passing the -f
option). It includes a
file field (using a @
option). The corresponding part of the
multipart request has a pseudo-header Content-Disposition
, but does
not have a pseudo-header Content-Type
.
How is it possible to add such a Content-Type
for a specific file?
For completeness, here is what I send now (as shown by -p B
):
--xyz
Content-Disposition: form-data; name="file"; filename="file.txt"
Hello, world!
This is the content of the file.
--xyz
but here is what I need to send:
--xyz
Content-Disposition: form-data; name="file"; filename="file.txt"
Content-Type: text/plain
Hello, world!
This is the content of the file.
--xyz
Or to put it another way, like the CURL equivalent option: -F "file=file.txt;type=text/plain"
.
I have just noticed that the documentation for multipart/form-data
now reads like the following (at the end):
When uploading files, their content type is inferred from the file name. You can manually override the inferred content type:
$ http -f POST httpbin.org/post name='John Smith' cv@'~/files/data.bin;type=application/pdf'
I do not know when that happened, but it seems that now:
Content-Type
" is inferred automaticallySo all I was looking for! :-)