Skip to content

Commit 203aaf9

Browse files
author
Oleksii Korshenko
committed
MAGETWO-64313: [GitHub] [PR] Fix CURL Json POST #3489 #8373
- added type string to parameter $param in order to support sending JSON or XML requests
1 parent e45441d commit 203aaf9

File tree

1 file changed

+13
-8
lines changed
  • lib/internal/Magento/Framework/HTTP/Client

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,18 @@ public function get($uri)
230230
/**
231231
* Make POST request
232232
*
233+
* String type was added to parameter $param in order to support sending JSON or XML requests.
234+
* This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373
235+
*
233236
* @param string $uri
234-
* @param array $params
235-
* @param bool $json
237+
* @param array|string $params
236238
* @return void
237239
*
238240
* @see \Magento\Framework\HTTP\Client#post($uri, $params)
239241
*/
240-
public function post($uri, $params, $json = false)
242+
public function post($uri, $params)
241243
{
242-
$this->makeRequest("POST", $uri, $params, $json = false);
244+
$this->makeRequest("POST", $uri, $params);
243245
}
244246

245247
/**
@@ -336,21 +338,24 @@ public function getStatus()
336338

337339
/**
338340
* Make request
341+
*
342+
* String type was added to parameter $param in order to support sending JSON or XML requests.
343+
* This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373
344+
*
339345
* @param string $method
340346
* @param string $uri
341-
* @param array $params
342-
* @param bool $json
347+
* @param array|string $params - use $params as a string in case of JSON or XML POST request.
343348
* @return void
344349
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
345350
* @SuppressWarnings(PHPMD.NPathComplexity)
346351
*/
347-
protected function makeRequest($method, $uri, $params = [], $json = false)
352+
protected function makeRequest($method, $uri, $params = [])
348353
{
349354
$this->_ch = curl_init();
350355
$this->curlOption(CURLOPT_URL, $uri);
351356
if ($method == 'POST') {
352357
$this->curlOption(CURLOPT_POST, 1);
353-
$this->curlOption(CURLOPT_POSTFIELDS, $json ? json_encode($params) : http_build_query($params));
358+
$this->curlOption(CURLOPT_POSTFIELDS, is_array($params) ? http_build_query($params) : $params);
354359
} elseif ($method == "GET") {
355360
$this->curlOption(CURLOPT_HTTPGET, 1);
356361
} else {

0 commit comments

Comments
 (0)