请求云服务器
@param  string   $path    请求的PATH
@param  string   $method  请求方法
@param  array    $headers 请求header
@param  resource $body    上传文件资源
@return boolean
198517
private function request($path, $method, $headers = null, $body = null){
	        $ch  = curl_init($path);

	        $_headers = array('Expect:');
	        if (!is_null($headers) && is_array($headers)){
	            foreach($headers as $k => $v) {
	                array_push($_headers, "{$k}: {$v}");
	            }
	        }

	        $length = 0;
			$date   = gmdate('D, d M Y H:i:s \G\M\T');

	        if (!is_null($body)) {
	            if(is_resource($body)){
	                fseek($body, 0, SEEK_END);
	                $length = ftell($body);
	                fseek($body, 0);

	                array_push($_headers, "Content-Length: {$length}");
	                curl_setopt($ch, CURLOPT_INFILE, $body);
	                curl_setopt($ch, CURLOPT_INFILESIZE, $length);
	            } else {
	                $length = @strlen($body);
	                array_push($_headers, "Content-Length: {$length}");
	                curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
	            }
	        } else {
	            array_push($_headers, "Content-Length: {$length}");
	        }

	        // array_push($_headers, 'Authorization: ' . $this->sign($method, $uri, $date, $length));
	        array_push($_headers, "Date: {$date}");

	        curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers);
	        curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
	        curl_setopt($ch, CURLOPT_HEADER, 1);
	        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);

	        if ($method == 'PUT' || $method == 'POST') {
				curl_setopt($ch, CURLOPT_POST, 1);
	        } else {
				curl_setopt($ch, CURLOPT_POST, 0);
	        }

	        if ($method == 'HEAD') {
	            curl_setopt($ch, CURLOPT_NOBODY, true);
	        }

	        $response = curl_exec($ch);
	        $status   = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	        curl_close($ch);
	        list($header, $body) = explode("\r\n\r\n", $response, 2);
	        if ($status == 200) {
	            if ($method == 'GET') {
	                return $body;
	            } else {
	                return $this->response($response);
	            }
	        } else {
	            $this->error($header , $body);
	            return false;
	        }
	    }
261651
protected function checkConnection($method, $path, $data, $headers)
    {
        $basicAuth = '';
        if ($this->options['username']) {
            $basicAuth .= "{$this->options['username']}:{$this->options['password']}@";
        }
        if ($this->options['headers']) {
            $headers = array_merge($this->options['headers'], $headers);
        }
        if (!isset($headers['Content-Type'])) {
            $headers['Content-Type'] = 'application/json';
        }
        $stringHeader = '';
        if ($headers != null) {
            foreach ($headers as $key => $val) {
                $stringHeader .= $key.': '.$val."\r\n";
            }
        }
        if ($this->httpFilePointer == null) {
            // TODO SSL support?
            $host = $this->options['host'];
            if ($this->options['port'] != 80) {
                $host .= ":{$this->options['port']}";
            }
            $this->httpFilePointer = @fopen(
                'http://'.$basicAuth.$host.$path,
                'r',
                false,
                stream_context_create(
                    [
                        'http' => [
                            'method'        => $method,
                            'content'       => $data,
                            'ignore_errors' => true,
                            'max_redirects' => 0,
                            'user_agent'    => 'Doctrine CouchDB ODM $Revision$',
                            'timeout'       => $this->options['timeout'],
                            'header'        => $stringHeader,
                        ],
                    ]
                )
            );
        }

        // Check if connection has been established successfully.
        if ($this->httpFilePointer === false) {
            $error = error_get_last();
            throw HTTPException::connectionFailure(
                $this->options['ip'],
                $this->options['port'],
                $error['message'],
                0
            );
        }
    }
1254842
public function custom(string $method, string $uri, string $body='', array $headers=[])
  {
    $this->sendRequest($this->createRequest($method,$uri), $headers);

    return !is_null($this->getResponse());
  }
167288
public function post($path, $postBody = null, array $parameters = [], $headers = [])
    {
        $response = $this->getClient()->getHttpClient()->post($path, $postBody, $parameters, $headers);

        return $this->decodeResponse($response);
    }
336355
private function _buildRequest($method, $path, $body = null, $contentType = null)
	{
		// copy default headers
		$headers = $this->_headers;

		// add Content-Type header if provided
		if ($contentType)
			$headers []= new HeaderField('Content-Type', $contentType);

		$request = new Request(
			$method,
			$this->_url->getUrlForRelativePath($path),
			$headers,
			$body
		);

		// pass the request through the filter chain
		foreach($this->_filters as $filter)
		{
			$request = $filter->request($request);
		}

		return $request;
	}
117473
private function processMethod($method, array $options, array $headers, array $body = [])
    {
        if ($method === 'get') {
            if ($body !== []) {
                throw new \Exception('Issuing a GET request with a body');
            }
            $options[CURLOPT_HTTPGET] = 1;
        } elseif ($method === 'post') {
            $data_string = json_encode($body);

            $options[CURLOPT_POST] = 1;
            $options[CURLOPT_POSTFIELDS] = $data_string;

            array_push($headers, 'Content-Type: application/json');
            array_push($headers, 'Content-Length: ' . strlen($data_string));
        } else {
            throw new \Exception('Unrecognized method ' . strtoupper($method));
        }

        return [$options, $headers];
    }
581178
public function put($path, $body = null, array $parameters = [], $headers = [])
    {
        $response = $this->getClient()->getHttpClient()->put($path, $body, $parameters, $headers);

        return $this->decodeResponse($response);
    }
832724
public function copy($headers = false, $body = false, $url = false, $method = false)
    {
        return clone $this;
    }
659567
public function run(
        string $method,
        string $uri,
        array $headers,
        string $body
    ) {
        if ($this->router === null) {
            return;
        }

        try {
            $response = $this->router->run($method, $uri, $headers, $body);
            if ($response !== null) {
                $response->output();
            }
        } catch (RouterException $e) {
            $e->getResponse()->output();
        }
    }
946565
public function createRequest($method = 'GET', $uri = null, $headers = null, $body = null, array $options = array())
    {
        $uri = '{+base_path}/' . ltrim($uri, '/');
        if ('GET' == $method && $this->usePostMethod($uri, $options)) {
            $method = 'POST';
            $body = $options['query'];
            unset($options['query']);
        }
        return parent::createRequest($method, $uri, $headers, $body, $options);
    }
116004
public function request(string $method, string $url, array $headers = [], string $body = ''): ResponseInterface
    {
        $request = Factory::request($method, $url, $headers, $body);

        return $this->sendRequest($request);
    }
413296
private function request(string $method, string $path, array $query = [], $body = null): string
    {
        // Prepare request:
        $query = build_query($query);
        $body = $this->parseBody($body);
        $path = trim($path, '/');
        $request = new Request(
            $method,
            "{$this->baseUri}/v3/$path/?$query",
            ['Content-Type' => 'application/json'],
            $body
        );

        return (string) $this->query($request)->getBody();
    }
97374
public function updateData($path, $body = "", array $opts = array())
    {
        $headers = array('Content-Type' => 'application/json');
        return empty($params)
            ? $this->_processResponse($this->http->put($this->_getApiPath($opts) . $path, $headers))
            : $this->_processResponse(
                $this->http->put(
                    $this->_getApiPath($opts) . $path,
                    $headers,
                    $body
                )
            );
    }
946668
private function createCurlOptions($method, $body = null, $headers = null)
    {
        $options = [
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_HEADER => true,
                CURLOPT_CUSTOMREQUEST => strtoupper($method),
                CURLOPT_SSL_VERIFYPEER => true,
                CURLOPT_FAILONERROR => false
            ] + $this->curlOptions;

        if (isset($headers)) {
            $headers = array_merge($this->headers, $headers);
        } else {
            $headers = $this->headers;
        }

        if (isset($body)) {
            $encodedBody = json_encode($body);
            $options[CURLOPT_POSTFIELDS] = $encodedBody;
            $headers = array_merge($headers, ['Content-Type: application/json']);
        }
        $options[CURLOPT_HTTPHEADER] = $headers;

        return $options;
    }
79810
public function send($method, $uri, $body = null, array $query = [], array $headers = [], array $options = [])
    {
        $this->validateMethod($method);

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

        $this->lastResponse = $this->client->send($method, $uri, $body, $query, $headers, $options);

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

        return $this->lastResponse;
    }
724070
protected function buildRequest(
        $method,
        $path,
        $data = null,
        array $headers = []
    ) {
        // Create basic request headers
        $host = "Host: {$this->options['host']}";
        if ($this->options['port'] != 80) {
            $host .= ":{$this->options['port']}";
        }
        $request = "$method $path HTTP/1.1\r\n$host\r\n";

        // Add basic auth if set
        if ($this->options['username']) {
            $request .= sprintf("Authorization: Basic %s\r\n",
                base64_encode($this->options['username'].':'.$this->options['password'])
            );
        }

        // Set keep-alive header, which helps to keep to connection
        // initialization costs low, especially when the database server is not
        // available in the locale net.
        $request .= 'Connection: '.($this->options['keep-alive'] ? 'Keep-Alive' : 'Close')."\r\n";

        if ($this->options['headers']) {
            $headers = array_merge($this->options['headers'], $headers);
        }
        if (!isset($headers['Content-Type'])) {
            $headers['Content-Type'] = 'application/json';
        }
        foreach ($headers as $key => $value) {
            if (is_bool($value) === true) {
                $value = ($value) ? 'true' : 'false';
            }
            $request .= $key.': '.$value."\r\n";
        }

        // Also add headers and request body if data should be sent to the
        // server. Otherwise just add the closing mark for the header section
        // of the request.
        if ($data !== null) {
            $request .= 'Content-Length: '.strlen($data)."\r\n\r\n";
            $request .= $data;
        } else {
            $request .= "\r\n";
        }

        return $request;
    }
1213833
public function rest($method, $url, $body = null, $headers = [], $options = [])
    {
        if (isset($headers['Content-Type']) && strpos($headers['Content-Type'], '/json') === false) {
            throw new InvalidValueException(['Content-Type of rest is not application/json: :content-type', 'content-type' => $headers['Content-Type']]);
        } else {
            $headers['Content-Type'] = 'application/json';
        }

        if (!isset($headers['X-Requested-With'])) {
            $headers['X-Requested-With'] = 'XMLHttpRequest';
        }

        if (!isset($headers['Accept'])) {
            $headers['Accept'] = 'application/json';
        }

        if (is_array($body)) {
            $body = json_encode($body, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        }

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

        if (!is_array($response->body)) {
            if (strpos($response->content_type, '/json') === false) {
                throw new ContentTypeException(['content-type of response is not application/json: :content-type => `:url`',
                    'content-type' => $response->content_type,
                    'url' => $response->url],
                    $response);
            }

            throw new JsonDecodeException(['json decode failed: `:url`', 'url' => $response->url], $response);
        }

        return $response;
    }