From 376a3448b6c10074fa5f62b26fc905ae801f5014 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Wed, 14 Dec 2022 15:08:23 +0700 Subject: [PATCH] add postData --- system/autoload/Http.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/system/autoload/Http.php b/system/autoload/Http.php index 0fd4da2b..e4b1982e 100644 --- a/system/autoload/Http.php +++ b/system/autoload/Http.php @@ -40,4 +40,26 @@ class Http curl_close($ch); return $server_output; } + + + public static function postData($url, $array_post, $headers = [], $basic = null) + { + $headers[] = 'Content-Type: application/x-www-form-urlencoded'; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); + curl_setopt($ch, CURLOPT_TIMEOUT, 15); + curl_setopt($ch, CURLOPT_VERBOSE, false); + curl_setopt($ch, CURLINFO_HEADER_OUT, false); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_post)); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + if (!empty($basic)) { + curl_setopt($ch, CURLOPT_USERPWD, $basic); + } + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $server_output = curl_exec($ch); + curl_close($ch); + return $server_output; + } }