plz.el
plz.el copied to clipboard
Support `multipart/form-data` `POST` requests
According to this SO post, multipart/form-data POST requests can be accomplished using curl like so:
curl -v -F key1=value1 -F upload=@localfilename URL
#4 shows an example of this also.
Appending things to plz-curl-default-args seems not to work very well. For example, the code below gives curl error 2 (Failed to initialize). The reason seems to be that the @- argument which is also added in this case is incompatible with -F.
(let* ((plz-curl-default-args
`("-F" "file=@/some/existing/file"
,@plz-curl-default-args)))
(plz 'post "https://httpbin.org/post"))
I think one could come up with a reasonable :body notation for form submissions along the lines of
(form (name "first-part" file "file1.txt" type "text/plain")
(name "second-part" body "some <i>text<i> in my form" type "text/html"))
Yeah, I didn't mean for users to modify the default args in order to send form data. :)
As for the body: I'll need to take another look at the spec to see how that works. It might be possible to send a form-data part and a non-form-data part, in which case using :body might be inappropriate. But anyway, specifying the form data could probably be done with one or more alists (or even just any map type using the map library).
Yes, I really want to get the form support, especially to upload file without reading to Emacs buffer with some additional text parameters. It would be very helpful if @astoff 's suggestion can be implemented.