diff --git a/async/cohttp_async.ml b/async/cohttp_async.ml index 3989a44081..bb76bb5eef 100644 --- a/async/cohttp_async.ml +++ b/async/cohttp_async.ml @@ -202,6 +202,11 @@ module Client = struct let post ?interrupt ?headers ?(chunked=false) ?body uri = call ?interrupt ?headers ~chunked ?body `POST uri + let post_form ?interrupt ?headers ~params uri = + let headers = Cohttp.Header.add_opt headers "content" "application/x-www-form-urlencoded" in + let body = Body.of_string (Uri.encoded_of_query params) in + post ?interrupt ~headers ~chunked:false ~body uri + let put ?interrupt ?headers ?(chunked=false) ?body uri = call ?interrupt ?headers ~chunked ?body `PUT uri diff --git a/async/cohttp_async.mli b/async/cohttp_async.mli index 1929a56b72..541fb48391 100644 --- a/async/cohttp_async.mli +++ b/async/cohttp_async.mli @@ -115,6 +115,14 @@ module Client : sig Cohttp.Code.meth -> Uri.t -> (Response.t * Body.t) Deferred.t + + (** Send an HTTP POST request in form format *) + val post_form: + ?interrupt:unit Deferred.t -> + ?headers:Cohttp.Header.t -> + params:(string * string list) list -> + Uri.t -> + (Response.t * Body.t) Deferred.t end module Server : sig