From 5ba64ee30a529f80681aa98cf86280572c5bd5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Tue, 31 Jan 2023 16:35:46 +0000 Subject: [PATCH] ezcurl: allow POST with non-form data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently ezcurl always sets CURLOPT_HTTPPOST, but that means it is not able to send a custom body that is not a form (e.g. JSON is quite a common use-case these days). Add a special case: if the POST params is empty, *and* a 'content' is set, then just set CURLOPT_POST, but not CURLOPT_HTTPPOST. Example usage: ``` let contents = Ezjsonm.to_string json in let config = EZ.Config.(verbose true default) in match EZ.post ~config ~url ~params:[] ~content:(`String contents) () with ``` Signed-off-by: Edwin Török --- src/core/Ezcurl_core.ml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/Ezcurl_core.ml b/src/core/Ezcurl_core.ml index 09999c3..f26216d 100644 --- a/src/core/Ezcurl_core.ml +++ b/src/core/Ezcurl_core.ml @@ -317,6 +317,8 @@ module Make(IO : IO) let resp_headers_done = ref false in (* once we get "\r\n" header line *) Curl.set_url self url; begin match meth with + | POST [] when (content <> None) -> + Curl.set_post self true | POST l -> Curl.set_httppost self l; | GET -> Curl.set_httpget self true; | PUT -> Curl.set_put self true;