Logs the request details.

@param string $name The name of the operation.
@param string $url API endpoint.
@param array  $headers Associative array of HTTP headers.
@param string $body The XML body of the POST request.
495869
private function logRequest($url, $name, $headers, $body)
    {
        if ($this->logger) {
            $this->logger->debug('Request', array(
                'url' => $url,
                'name' => $name,
                'headers' => $headers,
                'body' => $body
            ));
        }
    }
688075
public function send($send_headers = false)
	{
		$body = $this->__toString();

		if ($send_headers)
		{
			$this->send_headers();
		}

		if ($this->body != null)
		{
			echo $body;
		}
	}
149257
protected function sendRequest($headers, $body)
    {
        $request = new Request(
            'POST',
            $this->ionicPushEndPoint,
            $headers,
            $body
        );
        $client = new Client();

        try {
            $response = $client->send($request);
            return $response;
        } catch (ClientException $e) {
            switch ($e->getCode()) {
                case 401:
                case 403: {
                    throw new PermissionDeniedException(
                        "Permission denied sending push", $e->getCode(), $e
                    );
                }
                case 400: {
                    throw new BadRequestException(
                        "Bad request sending push", 400, $e
                    );
                }
            }
        } catch (\Exception $e) {
            throw new RequestException(
                "An error occurred when sending push request with message: {$e->getMessage()}",
                $e->getCode(),
                $e
            );
        }

        return null;
    }
29670
public function post($url, array $data, array $headers = null)
    {
        $headers = is_null($headers) ? ['Content-Type: application/json; charset=utf-8'] : $headers;
        return $this->sendRequest('POST', $url, $headers, $data);
    }
1257836
protected function log($url, $api, $parameters)
    {

        if ($this->logger !== null) {
            $this->logger->debug(
                $url,
                array(
                    'api' => $api,
                    'parameters' => $parameters
                )
            );
        }
    }
163891
private function saveHeaders ($header, &$headers)
    {
        if ($headers === NULL)
        {
            return;
        }

        $header       = explode("\r\n", $header);
        $headers      = array();
        $headerLength = count($header);

        // The 1st element is the HTTP code, so we can safely skip it
        for ($i = 1; $i < $headerLength; $i++)
        {
            list($key, $val) = explode(":", $header[$i]);
            $headers[$key] = trim($val);
        }
    }
470451
public function request($url, $method = 'GET', $headers = [], $body = null, $options = [])
    {
        if (false === is_array($options)) {
            $options = [];
        }

        $request = $this->getGuzzleClient()->createRequest($method, $url, $options);

        $request->addHeaders($headers);
        $request->setBody($body);

        $response = $this->getGuzzleClient()->send($request);

        return [
            'code'    => $response->getStatusCode(),
            'headers' => $response->getHeaders(),
            'body'    => (string)$response->getBody(),
        ];
    }
769876
public function httpRequest(
        string $method, string $uri, array $headers = [], array $body = []): EsiResponse
    {

        // Include some basic headers to those already passed in. Everything
        // is considered to be Json.
        $headers = array_merge($headers, [
            'Accept'       => 'application/json',
            'Content-Type' => 'application/json',
            'User-Agent'   => 'Eseye/' . Eseye::VERSION . '/' .
                Configuration::getInstance()->http_user_agent,
        ]);

        // Add some debug logging and start measuring how long the request took.
        $this->logger->debug('Making ' . $method . ' request to ' . $uri);
        $start = microtime(true);

        // Json encode the body if it has data, else just null it
        if (count($body) > 0)
            $body = json_encode($body);
        else
            $body = null;

        try {

            // Make the _actual_ request to ESI
            $response = $this->getClient()->send(
                new Request($method, $uri, $headers, $body));

        } catch (ClientException | ServerException $e) {

            // Log the event as failed
            $this->logger->error('[http ' . $e->getResponse()->getStatusCode() . ', ' .
                strtolower($e->getResponse()->getReasonPhrase()) . '] ' .
                $method . ' -> ' . $this->stripRefreshTokenValue($uri) . ' [t/e: ' .
                number_format(microtime(true) - $start, 2) . 's/' .
                implode(' ', $e->getResponse()->getHeader('X-Esi-Error-Limit-Remain')) . ']'
            );

            // Grab the body from the StreamInterface intance.
            $responseBody = $e->getResponse()->getBody()->getContents();

            // For debugging purposes, log the response body
            $this->logger->debug('Request for ' . $method . ' -> ' . $uri . ' failed. Response body was: ' .
                $responseBody);

            // Raise the exception that should be handled by the caller
            throw new RequestFailedException($e, $this->makeEsiResponse(
                $responseBody,
                $e->getResponse()->getHeaders(),
                'now',
                $e->getResponse()->getStatusCode())
            );
        }

        // Log the successful request.
        $this->logger->log('[http ' . $response->getStatusCode() . ', ' .
            strtolower($response->getReasonPhrase()) . '] ' .
            $method . ' -> ' . $this->stripRefreshTokenValue($uri) . ' [t/e: ' .
            number_format(microtime(true) - $start, 2) . 's/' .
            implode(' ', $response->getHeader('X-Esi-Error-Limit-Remain')) . ']'
        );

        // Return a container response that can be parsed.
        return $this->makeEsiResponse(
            $response->getBody()->getContents(),
            $response->getHeaders(),
            $response->hasHeader('Expires') ? $response->getHeader('Expires')[0] : 'now',
            $response->getStatusCode()
        );
    }
930244
public function post($uri,array $headers,$body)
        {
            return $this->prepareRequest(self::POST,$uri,$headers,$body);
        }
1121597
public function post($url, $data, array $headers = array())
    {
        curl_setopt($this->handle, CURLOPT_POST, true);
        curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);

        return $this->execute($url, $headers);
    }
142506
private function processRequest($url, $headers, $method = 'post')
    {
        if (array_key_exists('body', $headers)) {
            $headers['body'] = json_encode($headers['body']);
        }

        if ($method == 'post') {
            $response = $this->guzzle->request('POST', $url, $headers);
        } elseif ($method == 'delete') {
            $response = $this->guzzle->request('DELETE', $url, $headers);
        } else {
            $params = $this->processGetParams($headers);
            $response = $this->guzzle->request('GET', $url . $params);
        }
        $response = $this->processResponse($response);

        return $response;
    }
258082
public function iSendARequestWithBody($method, $url, PyStringNode $body)
    {
        $this->restApiBrowser->sendRequest($method, $url, (string) $body);
    }
132166
protected function get($url, array $headers)
    {
        $request = [
            'headers' => array_merge(
                ['Content-Type' => 'application/json'],
                $headers
            ),
            'exceptions' => false,
        ];

        $this->request('get', $url, $request);
    }
333268
protected function setPluginHeaders(string $name, array $headers)
    {
        $this->info('Set plugin headers...');

        $path = $this->path($name.'/plugin-name.php');
        $handle = fopen($path, 'r');
        $content = [];

        while (($line = fgets($handle)) !== false) {
            $content[] = $this->parseLine($line, $headers);
        }

        fclose($handle);

        $this->files->put($path, implode('', $content), true);
    }
287125
public static function post($url, $params, $headers=null)
	{
		$self = new self();
		if ( is_array($params) ) {
			$params = http_build_query($params);
		}
		$curl = $self->_curlInit($url, $headers);
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $params);

		return $self->_doRequest($curl, false);
	}
238412
public function sendHeader(string $name, ?string $value): void
    {
        if (headers_sent($file, $line)) {
            throw new HttpException(sprintf("Cannot use '%s()', headers already sent in %s:%s",
                __method__, $file, $line));
        }

        // null means remove
        if ($value === null) {
            $this->removeHeader($name);
            header_remove($name);
        } else {
            $this->setHeader($name, $value);
            header(sprintf('%s: %s', $name, $value));
        }
    }
528864
protected function delete($url, array $headers)
    {
        $request = [
            'headers' => array_merge(
                ['Content-Type' => 'application/json'],
                $headers
            ),
            'exceptions' => false,
        ];

        $this->request('delete', $url, $request);
    }