Sends a post request to the OAuth endpoint
Supports both guzzle 5 and 6 versions.

@param array $body

@return mixed
557937
private function sendPostRequest(array $body)
    {
        $requestBodyKey = version_compare(ClientInterface::VERSION, '6.0', '>=') ? 'form_params' : 'body';
        $response = $this->httpClient->post('', [
            $requestBodyKey => $body,
        ]);

        return \json_decode($response->getBody(), true);
    }
1096792
protected function _send_patch_request( $url, $body ) {
		$response = $this->_send_request( $url, array(
			'method' => 'PATCH',
			'body'   => $body,
		) );

		$response_code = wp_remote_retrieve_response_code( $response );
		$this->assertEquals( 200, $response_code, 'The Mailtrap.io API resonse code is not equals to 200.' );

		return $response;
	}
112937
protected function getResponse(array $headers, $body)
    {
        // Create the response object.
        $return = new Response();

        // Set the body for the response.
        $return->getBody()->write($body);

        $return->getBody()->rewind();

        // Get the response code from the first offset of the response headers.
        preg_match('/[0-9]{3}/', array_shift($headers), $matches);
        $code = $matches[0];

        if (is_numeric($code)) {
            $return = $return->withStatus($code);
        } elseif (!$this->getOption('allow_empty_status_code', false)) {
            // No valid response code was detected.
            throw new \UnexpectedValueException('No HTTP response code found.');
        }
        // Add the response headers to the response object.
        foreach ($headers as $header) {
            $pos = strpos($header, ':');

            $return = $return->withHeader(trim(substr($header, 0, $pos)), trim(substr($header, ($pos + 1))));
        }

        return $return;
    }
535078
public function sendAsync($method, $uri, $body = null, array $query = [], array $headers = [], array $options = [])
    {
        try {
            $this->validateMethod($method);
        } catch (\InvalidArgumentException $e) {
            return rejection_for($e);
        }

        $query = array_merge($this->getDefaultQuery(), $query);
        $headers = array_merge($this->getDefaultHeaders(), $headers);

        return $this->client->sendAsync($method, $uri, $body, $query, $headers, $options)->then(
            function (ResponseInterface $response) {
                $this->lastResponse = $response;

                $this->validateResponse($this->lastResponse);

                return $this->lastResponse;
            }
        );
    }
89982
public function post(string $query, ?string $body = null): ResponseInterface
    {
        $options = [
            'headers' => $this->getAuthorizationHeader(),
        ];

        if ($body) {
            $options['body'] = $body;
        }

        return $this->client->request('post', $this->buildQuery($query), $options);
    }
833495
public function body($body = null)
    {
        if (!is_null($body)) {
            $this->write($body, true);
        }

        return $this->body;
    }
215610
protected function send($method, $endpoint = '', array $headers = null, $body = null)
    {
        $this->lastResponse = null;
        $url = $this->baseUrl . $endpoint;
        $options = ['headers' => \array_merge($this->defaultHeaders, $headers)];

        if (!empty($body)) {
            $options['body'] = $body;
        }

        $this->lastRequest = $this->httpClient->request(
            $method,
            $url,
            $options
        );

        try {
            $this->lastResponse = $this->httpClient->send($this->lastRequest);
        } catch (\Exception $error) {
            throw new HttpServiceException(
                HttpServiceException::BAD_SERVICE_REQUEST,
                [$error->getMessage()]
            );
        }

        return $this->lastResponse;
    }
1303010
private static function requestApi($method, $body=null, $id=null) {
        $uri = Params::ENDPOINT . '/orders';
        if ($method == "get" || $method == "put")
            $uri .= "/$id";

        $request = new HttpRequest($method, $uri, self::$useSSL, self::$additionalCurlOpts);
        $request->setBasicAuthorization(self::$key);
        if (!is_null($body)) $request->setBodyAsJson($body);

        $response = $request->send();
        $response->checkCurlResponse();
        $jsonBody = $response->getBodyAsJson();
        if (!$response->isOk() || is_null($jsonBody) || !self::isBodyStatusOk($jsonBody)) {
            $httpStatus = $response->getHttpStatus();
            throw Exceptions\KondutoException::buildFromHttpStatus($jsonBody, $httpStatus);
        }

        return $response;
    }
870315
protected function getResponse(array $headers, $body)
	{
		// Create the response object.
		$return = new Response;

		// Set the body for the response.
		$return->body = $body;

		// Get the response code from the first offset of the response headers.
		preg_match('/[0-9]{3}/', array_shift($headers), $matches);
		$code = $matches[0];

		if (is_numeric($code))
		{
			$return->code = (int) $code;
		}

		// No valid response code was detected.
		else
		{
			throw new \UnexpectedValueException('No HTTP response code found.');
		}

		// Add the response headers to the response object.
		foreach ($headers as $header)
		{
			$pos = strpos($header, ':');
			$return->headers[trim(substr($header, 0, $pos))] = trim(substr($header, ($pos + 1)));
		}

		return $return;
	}
1016194
public function setBody($body) {
    if (is_array($body) || is_object($body))
      $this->body = (object) $body;
    else
      $this->body = $body;
    return $this;
  }
1240385
public function call($uri, array $params, $body, $method) {
        $path = "/v" . self::API_VERSION . "/" . self::API_TYPE . "{$uri}";
        $url = $this->host . $path;

        $items = array();
        $items['method'] = $method;
        $items['request_path'] = $path;
        $items['content_type'] = "application/json";
        $items['accept_language'] = "zh-cn";
        $items['date'] = gmdate('Y-m-d\TH:i:s\Z');
        $items['opensearch_headers'] = array();
        $items['content_md5'] = "";
        $items['opensearch_headers']['X-Opensearch-Nonce'] = $this->_nonce();

        if ($method != self::METHOD_GET) {
            if (!empty($body)) {
                $items['content_md5'] = md5($body);
                $items['body_json'] = $body;
            }
        }
        $items['query_params'] = $params;

        $signature = $this->_signature($this->secret, $items);
        $items['authorization'] = "OPENSEARCH {$this->accessKey}:{$signature}";

        return $this->_curl($url, $items);
    }
374553
public function setBody($body)
    {
        $body = json_encode($body);

        if ($error = json_last_error()) {
            throw new \ErrorException($error);
        }

        curl_setopt($this->curlHandler, CURLOPT_POSTFIELDS, $body);

        return $this;
    }
131366
public function send($endpoint, $options = [], $body = '')
    {
        return $this->client->post(
            $endpoint . '?' . http_build_query($options),
            [
                'body' => $body,
            ]
        );
    }
682246
public function post($url, $requestBody = null) {
        $posturl = $this->url . $url;
        return $this->restRequest($posturl, 'POST', $requestBody);
    }
649995
protected function httpPostJson($uri, $body)
    {
        $this->log[] = [
                        'request' => [
                                    'method' => 'POST',
                                    'uri'    => $uri,
                                    'body'   => $body,
                                    ],
                        ];
        $response = \Httpful\Request::post($uri)
                                                ->addHeader('X-Auth-Email', $this->email)
                                                ->addHeader('X-Auth-Key', $this->apikey)
                                                ->sendsAndExpects(\Httpful\Mime::JSON)
                                                ->parseWith(function ($body) {
                                                    return \Metaclassing\Utility::decodeJson($body);
                                                })
                                                ->body($body)
                                                ->send()
                                                ->body;
        $this->log[count($this->log) - 1]['response'] = $response;
        if ($response['success'] != true) {
            throw new \Exception("post to {$uri} unsuccessful");
        }

        return $response['result'];
    }
323843
public function chargeToken($body)
    {
        $request = $this->paystackHttpClient->post(
            Resource::CHARGE_TOKEN,
            [
                'body'  => is_array($body) ? $this->toJson($body) : $body,
            ]
        );

        return $this->processResourceRequestResponse($request);
    }
154856
protected function instance(string $body, int $status = 200, array $headers = []) : Response
    {
        $response = new Response('php://memory', $status, $headers);
        $response->getBody()->write($body);

        return $response;
    }