Skip to content

Commit fee221f

Browse files
author
Stanislav Idolov
authored
ENGCOM-1121: [Backport 2.1] Add json and xml support to the post method in socket client #14348
2 parents 18bf10a + 77601fc commit fee221f

File tree

1 file changed

+6
-4
lines changed
  • lib/internal/Magento/Framework/HTTP/Client

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ protected function parseUrl($uri)
273273
* Make POST request
274274
*
275275
* @param string $uri
276-
* @param array $params
276+
* @param array|string $params use string in case of JSON or XML POST request
277277
* @return void
278278
*/
279279
public function post($uri, $params)
@@ -455,10 +455,12 @@ public function getStatus()
455455

456456
/**
457457
* Make request
458+
*
458459
* @param string $method
459460
* @param string $uri
460-
* @param array $params
461+
* @param array|string $params use string in case of JSON or XML POST request
461462
* @return void
463+
* @throws \Exception
462464
*/
463465
protected function makeRequest($method, $uri, $params = [])
464466
{
@@ -473,8 +475,8 @@ protected function makeRequest($method, $uri, $params = [])
473475

474476
$appendHeaders = [];
475477
$paramsStr = false;
476-
if ($isPost && count($params)) {
477-
$paramsStr = http_build_query($params);
478+
if ($isPost && $params) {
479+
$paramsStr = is_array($params) ? http_build_query($params) : $params;
478480
$appendHeaders['Content-type'] = 'application/x-www-form-urlencoded';
479481
$appendHeaders['Content-length'] = strlen($paramsStr);
480482
}

0 commit comments

Comments
 (0)