@param string $url
@param string $method
@param array  $params
@param array  $options

@return array
559763
protected function request($url, $method = self::GET, $params = array(), $options = array())
    {
        if (in_array($method, array(self::GET, self::DELETE)) && count($params)) {
            $url .= (stripos($url, '?') ? '&' : '?') . http_build_query($params);
            $params = array();
        }

        curl_setopt($this->curl, CURLOPT_HEADER, true);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);

        curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($this->curl, CURLOPT_URL, $url);

        curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($this->curl, CURLOPT_TIMEOUT, 30);

        // File Upload
        if (isset($options['files']) && count($options['files']) > 0) {
            foreach ($options['files'] as $index => $file) {
                $params[$index] = $this->createCurlFile($file);
            }
            version_compare(PHP_VERSION, '5.5', '<') || curl_setopt($this->curl, CURLOPT_SAFE_UPLOAD, false);
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
        } elseif (isset($options['xml'])) {
            $options['headers'][] = 'content-type:text/xml';
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params['xml']);
        } elseif (isset($options['json'])) {
            $options['headers'][] = 'content-type:application/json';
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, Json::encode($params));
        } elseif (in_array($method, array(self::POST))) {
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($params));
        } else {

        }

        // Check for custom headers
        if (isset($options['headers']) && count($options['headers']))
            curl_setopt($this->curl, CURLOPT_HTTPHEADER, $options['headers']);

        // Check for basic auth
        if (isset($options['auth']['type']) && 'basic' === $options['auth']['type'])
            curl_setopt($this->curl, CURLOPT_USERPWD, $options['auth']['username'] . ':' . $options['auth']['password']);

        $response = $this->doCurl();
        // Separate headers and body
        $headerSize = $response['curl_info']['header_size'];
        $header = substr($response['response'], 0, $headerSize);
        $body = substr($response['response'], $headerSize);
        $results = array(
            'curl_info' => $response['curl_info'],
            'content_type' => $response['curl_info']['content_type'],
            'status' => $response['curl_info']['http_code'],
            'headers' => $this->splitHeaders($header),
            'data' => $body,
        );
        if ($response['response'] === false)
            $results['curl_error'] = curl_error($this->curl);
        return $results;
    }
33992
public function getAuthenticatedRequest($method, $url, $token, array $options = [])
    {
        $parsedUrl = parse_url($url);
        $queryString = array();

        if (isset($parsedUrl['query'])) {
            parse_str($parsedUrl['query'], $queryString);
        }

        if (!isset($queryString['access_token'])) {
            $queryString['access_token'] = (string) $token;
        }

        $url = http_build_url($url, [
            'query' => http_build_query($queryString),
        ]);

        return $this->createRequest($method, $url, null, $options);
    }
100621
public function getAuthenticatedRequest($method, $url, $token, array $options = [])
    {
        return $this->createRequest($method, $url, $token, $options);
    }
346183
public function requestRaw(string $url, string $method = 'GET', array $options = [])
    {
        return Response::buildFromPsrResponse($this->request($url, $method, $options, true));
    }
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(),
        ];
    }
824167
protected function sendRequest(string $method, string $uri, array $options = []): array
    {
        $request = $this->client->createRequest($method, $uri);

        $key = $method === Api::GET ? 'query' : 'form_params';
        $options[$key] = $this->signRequest(
            $method,
            $request->getUri()->__toString(),
            $options[$key] ?? []
        );

        return $this->processResponse(
            $this->client->send($request, $options)
        );
    }
160100
public function request($method, $url, $options)
    {
        $this->_curl = curl_init();
        $this->setUrl($url);
        $this->_setHttpVersionOption();
        $this->setHttpMethodOption($method);
        if (is_array($options) && !empty($options)) {
            self::setOptions($this->_curl, $options);
        }
        return new Response($this->_curl);
    }
1342406
public function send($method, $uri, array $options = [])
    {
        $this->calls[] = array('send', $method, $uri, $options);

        return new Response();
    }
279264
public function commit($method, $url, $params = [], $options = [])
    {
        $userAgent = [
            'bindings_version' => $this->config['version'],
            'lang'             => 'php',
            'lang_version'     => phpversion(),
            'publisher'        => 'conekta',
            'uname'            => php_uname(),
        ];

        $request = [
            'exceptions'      => false,
            'timeout'         => '80',
            'connect_timeout' => '30',
            'headers'         => [
                'Accept'                      => "application/vnd.conekta-v{$this->config['version']}+json",
                'Accept-Language'             => $this->config['locale'],
                'Authorization'               => 'Basic '.base64_encode($this->config['private_key'].':'),
                'Content-Type'                => 'application/json',
                'RaiseHtmlError'              => 'false',
                'X-Conekta-Client-User-Agent' => json_encode($userAgent),
                'User-Agent'                  => 'Conekta PayMeBindings/'.$this->config['version'],
            ],
        ];

        if (!empty($params)) {
            $request[$method === 'get' ? 'query' : 'json'] = $params;
        }

        $rawResponse = $this->getHttpClient()->{$method}($url, $request);
        $statusCode = $rawResponse->getStatusCode();

        $response = $statusCode == 200
            ? $this->parseResponse($rawResponse->getBody())
            : $this->responseError($rawResponse->getBody(), $statusCode);

        return $this->respond($response);
    }
785325
protected function request($url, $method = self::GET, $params = array(), $options = array())
    {
        $paths = parse_url($url);

        $host = $paths['host'];
        $is_ssl = isset($paths['scheme']) && $paths['scheme'] == 'https';
        $port = isset($paths['port']) ? $paths['port'] : ($is_ssl ? 443 : 80);

        $ip = \co::gethostbyname($host);
        if ( !$ip ) {
            \throw_error('co::gethostbyname("'. $host .'") host is empty', 19220);
        }

        $cli = new \Swoole\Coroutine\Http\Client($ip, $port, $is_ssl);

        // 兼容httpclient的header头
        $headers = ['Host' => $host];
        if (isset($options['headers']) && count($options['headers'])) {
            foreach ($options['headers'] as $value) {
                $tmp = explode(':', $value);
                if (\count($tmp) > 1) {
                    $headers[ $tmp[0] ] = implode(':', array_slice($tmp, 1));
                }
            }
        }

        $uri = (isset($paths['path']) ? $paths['path'] : '/') . '?' . (isset($paths['query']) ? $paths['query'] : '');

        // Set request timeout
        $cli->set(['timeout' => isset($options['timeout']) ? $options['timeout'] * 1000 : 10e3 ]);

        // Support get, post
        if ( $method === self::GET ) {
            $uri .= '&' . http_build_query($params);
            $cli->setHeaders($headers);
            $cli->get( $uri );
        } else if ( $method === self::POST ) {
            if ( !empty($options['json']) ) {
                $params = json_encode($params, JSON_UNESCAPED_UNICODE);
                $headers['Content-type'] = 'application/json';
            }

            // Check for files
            if (isset($options['files']) && count($options['files'])) {
                foreach ($options['files'] as $index => $file) {
                    $cli->addFile($file, $index);
                }
            }

            $cli->setHeaders($headers);
            $cli->post( $uri, $params );
        } else {
            \throw_error('Unsupported method, only GET/POST', 18201);
        }

        // Close
        $cli->close();

        return (object)array(
            'status_code'  => $cli->statusCode,
            // 'headers'      => [],
            'body'         => $cli->body,
        );
    }
682702
public function request($method, $url, array $params = [])
    {
        if (!$this->authenticated()) {
            $this->authenticate();
        }

        if (!isset($params['query'])) {
            $params['query'] = [];
        }

        $params['query']['format'] = 'json';

        try {
            $response = $this->getHttpClient()->request($method, $url, $params);
        } catch (RequestException $e) {
            return $e->getResponse();
        }

        return $response;
    }
654844
protected function request($method, $url, $options = [])
    {
        $client = $this->getClient();
        try {
            $response = $client->request($method, $url, $options);
        } catch (\GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();
            throw new PeopleMatterException($response->getStatusCode().": ".$response->getReasonPhrase(), 1, $e);
        }

        $body = $response->getBody();
        if (!is_array($body)) {
            $json = json_decode($body, true);
        } else {
            $json = $body;
        }

        if (!empty($json["ErrorMessage"])) {
            throw new PeopleMatterException($json["ErrorMessage"], $json["ErrorCode"]);
        }

        return $json;
    }
908683
public function request($url, $method = 'GET', $options = [])
    {
        $method = strtoupper($method);

        $options = array_merge(self::$defaults, $options);

        Log::debug('Client Request:', compact('url', 'method', 'options'));

        $options['handler'] = $this->getHandler();

        if (property_exists($this, 'baseUri') && !is_null($this->baseUri)) {
            $options['base_uri'] = $this->baseUri;
        }

        $response = $this->getClient()->request($method, $url, $options);

        Log::debug('API response:', [
            'Status' => $response->getStatusCode(),
            'Reason' => $response->getReasonPhrase(),
            'Headers' => $response->getHeaders(),
            'Body' => strval($response->getBody()),
        ]);

        return $response;
    }
763
public function commit($method, $url, $params = [], $options = [])
    {
        if (empty($this->connectionToken)) {
            $this->loginApplication();
        }

        $request = [
            'exceptions'      => false,
            'timeout'         => '80',
            'connect_timeout' => '30',
            'headers'         => [
                'Content-Type'  => 'application/json',
                'Accept'        => 'application/json',
                'Authorization' => 'Bearer '.$this->connectionToken,
            ],
        ];

        if (!empty($params)) {
            $request[$method === 'get' ? 'query' : 'json'] = $params;
        }

        $raw = $this->getHttpClient()->{$method}($url, $request);
        $statusCode = $raw->getStatusCode();

        $response = $statusCode == 200
            ? $this->parseResponse($raw->getBody())
            : $this->responseError($raw->getBody(), $statusCode);

        return $this->respond($response);
    }
384405
public function commit($method, $url, $params = [], $options = [])
    {
        $userAgent = [
            'bindings_version' => $this->config['version'],
            'lang'             => 'php',
            'lang_version'     => phpversion(),
            'publisher'        => 'stripe',
            'uname'            => php_uname(),
        ];

        $success = false;

        $request = [
            'exceptions'      => false,
            'timeout'         => '80',
            'connect_timeout' => '30',
            'headers'         => [
                'Authorization'              => 'Basic '.base64_encode($this->config['private_key'].':'),
                'Content-Type'               => 'application/x-www-form-urlencoded',
                'RaiseHtmlError'             => 'false',
                'User-Agent'                 => 'Stripe/v1 PayMeBindings/'.$this->config['version'],
                'X-Stripe-Client-User-Agent' => json_encode($userAgent),
            ],
        ];

        if (version_compare(ClientInterface::VERSION, '6') === 1) {
            $request['form_params'] = $params;
        } else {
            $request['body'] = $params;
        }

        $rawResponse = $this->getHttpClient()->{$method}($url, $request);

        if ($rawResponse->getStatusCode() == 200) {
            $response = $this->parseResponse($rawResponse->getBody());
        } else {
            $response = $this->responseError($rawResponse->getBody());
        }

        return $this->respond($success, $response);
    }
1357776
public function requestAsync($method, $url, $options)
    {
        $request = $this->authClient->getAuthenticatedRequest($method, $url, $this->getAccessToken());

        return $this->httpClient->sendAsync($request, $options);
    }
159240
public static function get($url, $query = [], $options = [])
    {
        $options['query'] = $query;
        return self::doRequest('get', $url, $options);
    }