From a164e75f79649ea587ab13afef1a96fb0bfa7c4b Mon Sep 17 00:00:00 2001 From: justanotheranonymoususer Date: Sun, 9 Apr 2023 00:53:55 +0300 Subject: [PATCH] Fix curlopt_postfields array to string conversion error --- Proxy.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Proxy.php b/Proxy.php index 5691aea..2d1636b 100644 --- a/Proxy.php +++ b/Proxy.php @@ -293,6 +293,21 @@ protected static function getIncomingRequestHeaders($skippedHeaders = []) return $results; } + // https://gist.github.com/yisraeldov/ec29d520062575c204be7ab71d3ecd2f + protected static function build_post_fields( $data,$existingKeys='',&$returnArray=[]){ + if(($data instanceof CURLFile) or !(is_array($data) or is_object($data))){ + $returnArray[$existingKeys]=$data; + return $returnArray; + } + else{ + foreach ($data as $key => $item) { + static::build_post_fields($item,$existingKeys?$existingKeys."[$key]":$key,$returnArray); + } + return $returnArray; + } + } + + /** * @param string $targetURL * @return false|resource @@ -324,7 +339,7 @@ protected static function createRequest($targetURL) } } - curl_setopt($request, CURLOPT_POSTFIELDS, $data + $_POST); + curl_setopt($request, CURLOPT_POSTFIELDS, static::build_post_fields($data + $_POST)); } $headers = static::getIncomingRequestHeaders(static::getSkippedHeaders());