From 4dba9213b89d1cbbed4f3badc2733bf3bae91363 Mon Sep 17 00:00:00 2001 From: PaskyAdigun Date: Sun, 21 Oct 2018 08:55:16 +0100 Subject: [PATCH 1/2] Allow json payload in request body --- lib/curl.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/curl.php b/lib/curl.php index 9d9497f..51af49c 100644 --- a/lib/curl.php +++ b/lib/curl.php @@ -168,7 +168,23 @@ function put($url, $vars = array()) { function request($method, $url, $vars = array()) { $this->error = ''; $this->request = curl_init(); - if (is_array($vars)) $vars = http_build_query($vars, '', '&'); + + $json_payload = ''; + if (strtolower('get') != 'get') { + foreach ($headers as $key => $value) { + if (strtolower($value) == 'application/json') { + $json_payload = json_encode($vars); + } + } + } + + if (is_array($vars)) { + if ($json_payload == '') { + $vars = http_build_query($vars, '', '&'); + }else { + $vars = $json_payload; + } + } $this->set_request_method($method); $this->set_request_options($url, $vars); From c9c9d90a471c272bd29c2faaa620e5199cd830b5 Mon Sep 17 00:00:00 2001 From: PaskyAdigun Date: Sun, 21 Oct 2018 08:59:26 +0100 Subject: [PATCH 2/2] Allow JSON payload in request body --- lib/curl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/curl.php b/lib/curl.php index 51af49c..b25b765 100644 --- a/lib/curl.php +++ b/lib/curl.php @@ -170,8 +170,8 @@ function request($method, $url, $vars = array()) { $this->request = curl_init(); $json_payload = ''; - if (strtolower('get') != 'get') { - foreach ($headers as $key => $value) { + if (strtolower($method) != 'get') { + foreach ($this->headers as $key => $value) { if (strtolower($value) == 'application/json') { $json_payload = json_encode($vars); }