Skip to content

Commit a676af8

Browse files
committed
Backport of 8373: Fix CURL Json POST
1 parent 08648cb commit a676af8

File tree

1 file changed

+10
-3
lines changed
  • lib/internal/Magento/Framework/HTTP/Client

1 file changed

+10
-3
lines changed

lib/internal/Magento/Framework/HTTP/Client/Curl.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,11 @@ public function get($uri)
222222
/**
223223
* Make POST request
224224
*
225+
* String type was added to parameter $param in order to support sending JSON or XML requests.
226+
* This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373
227+
*
225228
* @param string $uri
226-
* @param array $params
229+
* @param array|string $params
227230
* @return void
228231
*
229232
* @see \Magento\Framework\HTTP\Client#post($uri, $params)
@@ -327,9 +330,13 @@ public function getStatus()
327330

328331
/**
329332
* Make request
333+
*
334+
* String type was added to parameter $param in order to support sending JSON or XML requests.
335+
* This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373
336+
*
330337
* @param string $method
331338
* @param string $uri
332-
* @param array $params
339+
* @param array|string $params - use $params as a string in case of JSON or XML POST request.
333340
* @return void
334341
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
335342
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -340,7 +347,7 @@ protected function makeRequest($method, $uri, $params = [])
340347
$this->curlOption(CURLOPT_URL, $uri);
341348
if ($method == 'POST') {
342349
$this->curlOption(CURLOPT_POST, 1);
343-
$this->curlOption(CURLOPT_POSTFIELDS, http_build_query($params));
350+
$this->curlOption(CURLOPT_POSTFIELDS, is_array($params) ? http_build_query($params) : $params);
344351
} elseif ($method == "GET") {
345352
$this->curlOption(CURLOPT_HTTPGET, 1);
346353
} else {

0 commit comments

Comments
 (0)