From a676af86fe11a6bc1ecf4e46fe413afeef4ac14f Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 16 Mar 2018 21:42:19 +0300 Subject: [PATCH] Backport of 8373: Fix CURL Json POST --- lib/internal/Magento/Framework/HTTP/Client/Curl.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/HTTP/Client/Curl.php b/lib/internal/Magento/Framework/HTTP/Client/Curl.php index d4271bdebe6cc..85508dbf9c1ff 100644 --- a/lib/internal/Magento/Framework/HTTP/Client/Curl.php +++ b/lib/internal/Magento/Framework/HTTP/Client/Curl.php @@ -222,8 +222,11 @@ public function get($uri) /** * Make POST request * + * String type was added to parameter $param in order to support sending JSON or XML requests. + * This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373 + * * @param string $uri - * @param array $params + * @param array|string $params * @return void * * @see \Magento\Framework\HTTP\Client#post($uri, $params) @@ -327,9 +330,13 @@ public function getStatus() /** * Make request + * + * String type was added to parameter $param in order to support sending JSON or XML requests. + * This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373 + * * @param string $method * @param string $uri - * @param array $params + * @param array|string $params - use $params as a string in case of JSON or XML POST request. * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) @@ -340,7 +347,7 @@ protected function makeRequest($method, $uri, $params = []) $this->curlOption(CURLOPT_URL, $uri); if ($method == 'POST') { $this->curlOption(CURLOPT_POST, 1); - $this->curlOption(CURLOPT_POSTFIELDS, http_build_query($params)); + $this->curlOption(CURLOPT_POSTFIELDS, is_array($params) ? http_build_query($params) : $params); } elseif ($method == "GET") { $this->curlOption(CURLOPT_HTTPGET, 1); } else {