Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions async/cohttp_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ module Client = struct

let delete ?interrupt ?headers uri =
call ?interrupt ?headers ~chunked:false `DELETE uri

let post_form ?interrupt ?headers ~params uri =
let headers = Cohttp.Header.add_opt headers "content-type" "application/x-www-form-urlencoded" in
let q = List.map ~f:(fun (k,v) -> k, [v]) (Cohttp.Header.to_list params) in
let body = Body.of_string (Uri.encoded_of_query q) in
post ?interrupt ~headers ~chunked:false ~body uri

end

module Server = struct
Expand Down
8 changes: 8 additions & 0 deletions async/cohttp_async.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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:Cohttp.Header.t ->
Uri.t ->
(Response.t * Body.t) Deferred.t
end

module Server : sig
Expand Down