diff --git a/lib/form.ml b/lib/form.ml index 8a4b83b..b62a1fc 100644 --- a/lib/form.ml +++ b/lib/form.ml @@ -1,18 +1,20 @@ open Lwt.Syntax -open Cohttp_lwt +open Cohttp_lwt_unix let post (url : Uri.t) (form_data : (string * string) list) = - let headers = Header.init_with "Content-Type" "application/x-www-form-urlencoded" in - let body = Uri.encoded_of_query form_data in - let* resp, body = Client.post ~headers ~body:(Body.of_string body) url in - let status = Response.status resp in - if Code.code_of_status status = 200 + let headers = Cohttp.Header.init_with "Content-Type" "application/x-www-form-urlencoded" in + let body = Uri.encoded_of_query (List.map (fun (k, v) -> k, [ v ]) form_data) in + let* resp, body = Client.post ~headers ~body:(Cohttp_lwt.Body.of_string body) url in + let status = Cohttp.Response.status resp in + if Cohttp.Code.code_of_status status = 200 then - let* body = Body.to_string body in + let* body = Cohttp_lwt.Body.to_string body in let json = Yojson.Basic.from_string body in Lwt.return (Some json) else ( let url_str = Uri.to_string url in - let* _ = Lwt_io.printl (Printf.sprintf "HTTP Error: %s for URL: %s" (Code.string_of_status status) url_str) in + let* _ = + Lwt_io.printl (Printf.sprintf "HTTP Error: %s for URL: %s" (Cohttp.Code.string_of_status status) url_str) + in Lwt.return None) ;;