创建一个URL请求
@access public
@param string    $uri URL地址
@param string    $method 请求类型
@param array     $params 请求参数
@param array     $cookie
@param array     $files
@param array     $server
@param string    $content
@return \think\Request
498803
public function create($uri, $method = 'GET', $params = [], $cookie = [], $files = [], $server = [], $content = null)
    {
        $server['PATH_INFO']      = '';
        $server['REQUEST_METHOD'] = strtoupper($method);
        $info                     = parse_url($uri);
        if (isset($info['host'])) {
            $server['SERVER_NAME'] = $info['host'];
            $server['HTTP_HOST']   = $info['host'];
        }
        if (isset($info['scheme'])) {
            if ('https' === $info['scheme']) {
                $server['HTTPS']       = 'on';
                $server['SERVER_PORT'] = 443;
            } else {
                unset($server['HTTPS']);
                $server['SERVER_PORT'] = 80;
            }
        }
        if (isset($info['port'])) {
            $server['SERVER_PORT'] = $info['port'];
            $server['HTTP_HOST']   = $server['HTTP_HOST'] . ':' . $info['port'];
        }
        if (isset($info['user'])) {
            $server['PHP_AUTH_USER'] = $info['user'];
        }
        if (isset($info['pass'])) {
            $server['PHP_AUTH_PW'] = $info['pass'];
        }
        if (!isset($info['path'])) {
            $info['path'] = '/';
        }
        $options                      = [];
        $options[strtolower($method)] = $params;
        $queryString                  = '';
        if (isset($info['query'])) {
            parse_str(html_entity_decode($info['query']), $query);
            if (!empty($params)) {
                $params      = array_replace($query, $params);
                $queryString = http_build_query($query, '', '&');
            } else {
                $params      = $query;
                $queryString = $info['query'];
            }
        } elseif (!empty($params)) {
            $queryString = http_build_query($params, '', '&');
        }
        if ($queryString) {
            parse_str($queryString, $get);
            $options['get'] = isset($options['get']) ? array_merge($get, $options['get']) : $get;
        }

        $server['REQUEST_URI']  = $info['path'] . ('' !== $queryString ? '?' . $queryString : '');
        $server['QUERY_STRING'] = $queryString;
        $options['cookie']      = $cookie;
        $options['param']       = $params;
        $options['file']        = $files;
        $options['server']      = $server;
        $options['url']         = $server['REQUEST_URI'];
        $options['baseUrl']     = $info['path'];
        $options['pathinfo']    = '/' == $info['path'] ? '/' : ltrim($info['path'], '/');
        $options['method']      = $server['REQUEST_METHOD'];
        $options['domain']      = isset($info['scheme']) ? $info['scheme'] . '://' . $server['HTTP_HOST'] : '';
        $options['content']     = $content;
        foreach ($options as $name => $item) {
            if (property_exists($this, $name)) {
                $this->$name = $item;
            }
        }
        return $this;
    }
231565
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
    {
        $this->currentUri = $this->prepareUrlForRequest($uri);

        $symfonyRequest = SymfonyRequest::create(
            $this->currentUri, $method, $parameters,
            $cookies, $files, $server, $content
        );

        $response = $this->app->prepareResponse(
            $this->app->handle(Request::createFromBase($symfonyRequest))
        );
        $this->response = $this->createTestResponse($response);

        return $this->response;
    }
952703
public function addUriWildcards($uri, $reflection, $method): string
    {
        $refAction = $reflection->getReflectionClass()->getMethod($method);

        $parameter = '';
        $patterns = $this->router->getPattern();
        $arguments = new \CachingIterator(new \ArrayIterator($refAction->getParameters()));

        foreach ($arguments as $key => $param) {
            if (!$param->isOptional()) {
                if (array_key_exists('{:' . $param->getName() . '}', $patterns)) {
                    $slash = ($arguments->hasNext()) ? '/' : '';
                    $parameter .= '{:' . $param->getName() . '}' . $slash;
                }
            }
        }

        return $uri . '/' . $parameter;
    }
1065890
public function run($uri, $method, array $queryParams = array(), array $body = array())
    {
        $url = sprintf('/%s%s', self::API_VERSION, $uri);

        return $this->runUrl($url, $method, $queryParams, $body);
    }
259657
function(uri, method, form) {
  this.method = method = method || 'GET';
  this.headers = {};
  this.url = uri;
  this.pathname = uri;
  this.cookies = {};
  this.params = [];

  if (document.cookie) {
    this.headers['Cookie'] = document.cookie;
    this.cookies = DOM.getCookies();
  }

  if (form) {
    var serial = DOM.serialize(form) || {};
    this.headers['Content-Type'] =
      form.enctype || 'application/x-www-form-urlencoded';
    if (method === 'GET') {
      this.query = serial.data;
      this.rawQuery = serial.encoded;
    } else {
      this.body = serial.data;
      this.rawBody = serial.encoded;
    }
    // method override
    if (serial.data & serial.data._method) {
      this.method = method = serial.data._method.toUpperCase();
    }
  }

  if (~uri.indexOf('?')) {
    uri = uri.split('?');
    this.query = parsePairs(uri[1], '&');
    this.rawQuery = uri[1];
    this.pathname = uri = uri[0];
  }
}
883865
protected function _doRequest($method, $uri, $options)
    {
        return $this->httpClient->request($method, $uri, $options);
    }
1213209
protected function makeRequest($method, $uri, $parameters = [], $cookies = [], $files = [])
    {
        $uri = $this->prepareUrlForRequest($uri);

        $this->call($method, $uri, $parameters, $cookies, $files);

        $this->clearInputs()->followRedirects()->assertPageLoaded($uri);

        $this->currentUri = $this->app->make('request')->fullUrl();

        $this->crawler = new Crawler($this->response->getContent(), $this->currentUri);

        return $this;
    }
1050067
public function createRequest($method, $uri, array $headers = [], $body = null, $protocol = '1.1')
    {
        if (is_array($body)) {
            $body = http_build_query($body, '', '&');
        }

        if ($method == 'GET') {
            $uri .= ((strpos('?', $uri) === false) ? '?' : '&').$body;
            $body = '';
        }

        return $this->requestFactory->createRequest($method, $uri, $headers, $body, $protocol);
    }
132425
public function request($method, $uri, array $parameters = [], array $options = [])
    {
        $parameters['key'] = $this->apiKey;
        $options['query'] = $parameters;

        $uri = $this->apiUrl.$uri.'/json';

        $this->log($method, $uri, $options);
        $response = $this->httpClient->request($method, $uri, $options);

        $result = $this->decoder->decode($response);

        if (!isset($result['status'])) {
            throw new ClientErrorException('Missing return status');
        }

        if (!in_array($result['status'], [
                'OK',
                'ZERO_RESULTS',
            ], true)) {
            throw new ClientErrorException(sprintf('Invalid return status "%s"', $result['status']));
        }

        return $result;
    }
952173
public function request($method, $url, $data = null)
    {
        $url = (string)$url;
        $data = array('$data' => $data);

        if (!$this->cache && $this->params['cache']) {
            $client_id = isset($this->params['route']['client'])
                ? $this->params['route']['client']
                : $this->params['client_id'];
            $this->cache = new Cache($client_id, $this->params['cache']);
        }

        try {
            if (!$this->server->connected) {
                if ($this->params['proxy']) {
                    $data = $this->request_proxy_data($data);
                }
                if (!$this->authed) {
                    $data['$client'] = isset($this->params['route']['client'])
                        ? $this->params['route']['client']
                        : $this->params['client_id'];
                    // Perform basic auth by default for secure/non-route based requests
                    if (!isset($this->server->options['clear']) && !isset($this->params['route']['client'])) {
                        $data['$key'] = $this->params['client_key'];
                        if ($this->cache) {
                            $data['$cached'] = $this->cache->get_versions();
                        }
                        if ($this->params['session']) {
                            $data['$session'] = $this->params['session'];
                        }
                    }
                }
                $this->server->connect();
            }
            $result = $this->server->request($method, $url, $data);
        } catch (NetworkException $e) {
            $this->request_rescue($e);
            $result = $this->server->request($method, $url, $data);
        }

        if (isset($result['$auth'])) {
            if (isset($result['$end'])) {
                // Connection ended, retry
                return $this->request($method, $url, $data['$data']);
            } else {
                $result = $this->auth($result['$auth']);
            }
        }

        return $this->response($method, $url, $data, $result);
    }
260966
public function callSecure($method, $uri, $parameters = [], $files = [], $server = [], $content = null)
    {
        $uri = 'https://localhost/'.ltrim($uri, '/');
        return $this->call($method, $uri, $parameters, $files, $server, $content);
    }
440140
public function sendRequest($method ,$uri = null)
    {

        $this->reset();

        try {
            //log request
            $this->setLog(LogLevel::INFO, 'Try to send Request: Method: '.$method.' uri: '.$uri, $this->requestHelper->options);

            //send request
            $this->response->psr7response = $this->httpclient->request($method, $uri, $this->requestHelper->options );

            //log headers
            $this->setLog(LogLevel::INFO, 'Request send with Headers: '.$this->getHeadersString($this->response->psr7response), $this->requestHelper->options);

            // To retrive body, do not use ->getContents()
            // it turns out that this gets the “remaining contents of the body as a string”
            // and since the middleware already accessed the body (for example in order to log it),
            // there isn’t any content remaining to retrieve.
            // The correct way to access the response content is to cast the body to a string.
            // See: https://michaelstivala.com/logging-guzzle-requests/
            $this->response->body = (string) $this->response->psr7response->getBody();

            //log status code
            $this->response->status_code =  $this->response->psr7response->getStatusCode();

            //log response
            $this->setLog(LogLevel::INFO,'Response ',['status code'=>$this->response->status_code,'body'=>$this->response->body]);

        } catch (\GuzzleHttp\Exception\ClientException $e) {

            $responseStatusCode = $this->getResponseStatusCodeFromException($e);
            $this->setLog(LogLevel::ERROR,'\GuzzleHttp\Exception\ClientException',['message'=>$e->getMessage(),'path request'=>$e->getRequest()->getUri()->getPath(),'method'=>$e->getRequest()->getMethod(),'response status code'=>$responseStatusCode]);
                                            $this->setLog(LogLevel::DEBUG,'\GuzzleHttp\Exception\ClientException',['trace'=>$e->getTraceAsString()]);
            throw new \GuzzleHttp\Exception\ClientException($e->getMessage().' '.$responseStatusCode,$e->getRequest(),$e->getResponse(),$e,$e->getHandlerContext());

        } catch (\GuzzleHttp\Exception\ServerException $e) {

            $responseStatusCode = $this->getResponseStatusCodeFromException($e);
            $this->setLog(LogLevel::ERROR,'\GuzzleHttp\Exception\ServerException',['message'=>$e->getMessage(),'path request'=>$e->getRequest()->getUri()->getPath(),'method'=>$e->getRequest()->getMethod(),'response status code'=>$responseStatusCode]);
            $this->setLog(LogLevel::DEBUG,'\GuzzleHttp\Exception\ServerException',['trace'=>$e->getTraceAsString()]);
            throw new \GuzzleHttp\Exception\ServerException($e->getMessage().' '.$responseStatusCode,$e->getRequest(),$e->getResponse(),$e,$e->getHandlerContext());


        } catch (\GuzzleHttp\Exception\BadResponseException $e) {

            $responseStatusCode = $this->getResponseStatusCodeFromException($e);
            $this->setLog(LogLevel::ERROR,'\GuzzleHttp\Exception\BadResponseException',['message'=>$e->getMessage(),'path request'=>$e->getRequest()->getUri()->getPath(),'method'=>$e->getRequest()->getMethod(),'response status code'=>$responseStatusCode]);
            $this->setLog(LogLevel::DEBUG,'\GuzzleHttp\Exception\BadResponseException',['trace'=>$e->getTraceAsString()]);
            throw new \GuzzleHttp\Exception\BadResponseException($e->getMessage().' '.$responseStatusCode,$e->getRequest(),$e->getResponse(),$e,$e->getHandlerContext());

        } catch (\GuzzleHttp\Exception\ConnectException $e) {

            $responseStatusCode = $this->getResponseStatusCodeFromException($e);
            $this->setLog(LogLevel::ERROR,'\GuzzleHttp\Exception\ConnectException',['message'=>$e->getMessage(),'path request'=>$e->getRequest()->getUri()->getPath(),'method'=>$e->getRequest()->getMethod(),'response status code'=>$responseStatusCode]);
            $this->setLog(LogLevel::DEBUG,'\GuzzleHttp\Exception\ConnectException',['trace'=>$e->getTraceAsString()]);
            throw new \GuzzleHttp\Exception\ConnectException($e->getMessage().' '.$responseStatusCode,$e->getRequest(),$e,$e->getHandlerContext());

        } catch (\GuzzleHttp\Exception\TooManyRedirectsException $e) {

            $responseStatusCode = $this->getResponseStatusCodeFromException($e);
            $this->setLog(LogLevel::ERROR,'\GuzzleHttp\Exception\TooManyRedirectsException',['message'=>$e->getMessage(),'path request'=>$e->getRequest()->getUri()->getPath(),'method'=>$e->getRequest()->getMethod(),'response status code'=>$responseStatusCode]);
            $this->setLog(LogLevel::DEBUG,'\GuzzleHttp\Exception\TooManyRedirectsException',['trace'=>$e->getTraceAsString()]);
            throw new \GuzzleHttp\Exception\TooManyRedirectsException($e->getMessage().' '.$responseStatusCode,$e->getRequest(),$e->getResponse(),$e,$e->getHandlerContext());

        } catch (\GuzzleHttp\Exception\RequestException $e) {

            $responseStatusCode = $this->getResponseStatusCodeFromException($e);
            $this->setLog(LogLevel::ERROR,'\GuzzleHttp\Exception\RequestException',['message'=>$e->getMessage(),'path request'=>$e->getRequest()->getUri()->getPath(),'method'=>$e->getRequest()->getMethod(),'response status code'=>$responseStatusCode]);
            $this->setLog(LogLevel::DEBUG,'\GuzzleHttp\Exception\RequestException',['trace'=>$e->getTraceAsString()]);
            throw new \GuzzleHttp\Exception\RequestException($e->getMessage().' '.$responseStatusCode,$e->getRequest(),$e->getResponse(),$e,$e->getHandlerContext());

        } catch (\GuzzleHttp\Exception\TransferException $e) {

            $this->setLog(LogLevel::ERROR,'\GuzzleHttp\Exception\TransferException',['message'=>$e->getMessage(),'code'=>$e->getCode()]);
            $this->setLog(LogLevel::DEBUG,'\GuzzleHttp\Exception\TransferException',['trace'=>$e->getTraceAsString()]);
            throw new \GuzzleHttp\Exception\TransferException($e->getMessage(),$e->getCode(),$e);

        } catch (\RuntimeException $e) {

            $this->setLog(LogLevel::ERROR,'\RuntimeException',['message'=>$e->getMessage(),'code'=>$e->getCode()]);
            $this->setLog(LogLevel::DEBUG,'\RuntimeException',['trace'=>$e->getTraceAsString()]);
            throw new \RuntimeException($e->getMessage(),$e->getCode(),$e);

        }

        return $this->response;
    }
600083
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
  {
    # Copied from Guzzles ::fromGlobals(), but we need to support the $server array as
    # paramter, so we use that instead of the $_SERVER array guzzle uses by default

    $method = isset($server['REQUEST_METHOD']) ? $server['REQUEST_METHOD'] : 'GET';
    $headers = \function_exists('getallheaders') ? \getallheaders() : [];
    $uri = $uri;
    $body = new LazyOpenStream('php://input', 'r+');
    $protocol = isset($server['SERVER_PROTOCOL']) ? \str_replace('HTTP/', '', $server['SERVER_PROTOCOL']) : '1.1';

    $serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $server);

    \logger()->debug('Created PSR-7 ServerRequest("'.$method.'","'.$url.'") (Guzzle)');

    return $serverRequest
        ->withCookieParams($_COOKIE)
        ->withQueryParams($_GET)
        ->withParsedBody($_POST)
        ->withUploadedFiles(ServerRequest::normalizeFiles($_FILES));
  }
271119
public function request($method, $uri, array $data = array())
    {
        $path = $this->path() . '/' . trim($uri, '/');

        $session = curl_init();

        // Curious as why i have to do this
        if ($method === 'PUT') {
            curl_setopt($session, CURLOPT_POSTFIELDS, http_build_query($data));
        } else {
            $path .= '?' . http_build_query($data);
        }

        curl_setopt($session, CURLOPT_HEADER, true);
        curl_setopt($session, CURLOPT_HTTPHEADER, $this->defaultHeaders());
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($session, CURLOPT_POST, $method !== 'GET');

        curl_setopt($session, CURLOPT_URL, $path);
        curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
        $response = curl_exec($session);
        $statusCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
        $headerSize = curl_getinfo($session, CURLINFO_HEADER_SIZE);
        $body = substr($response, $headerSize);

        if ($statusCode !== 200) {
            throw new InvalidRequest($body);
        }

        curl_close($session);

        return json_decode($body, true);
    }
49525
public function send($uri, $method, array $headers = [], $datas = [], array $files = [])
    {
        return $this->sendRequest($this->getConfiguration()->getMessageFactory()->createInternalRequest(
            $uri,
            $method,
            $this->getConfiguration()->getProtocolVersion(),
            $headers,
            $datas,
            $files
        ));
    }
204378
public function createRequest($method, $uri){
        if(!is_string($method)){
            throw new \InvalidArgumentException();
        }else if(!is_string($uri) && !($uri instanceof UriInterface)){
            throw new \InvalidArgumentException();
        }

        if(is_string($uri)){
            $uri    = new Uri($uri);
        }

        return new Request($method, $uri);
    }
839990
public function request($method, $params = [], $files = [])
    {
        $url = sprintf('%s/%s/%s_%s', self::BASE_API, $this->classify, $this->classify, strtolower($method));
        if (!array_key_exists(strtolower($method), $this->filter)) {
            throw new NotFoundException(sprintf('the url %s can not found!please reaffirm', $url));
        }
        $factory = new ValidatorFactory(new Translator());
        $validator = $factory->make($params, $this->filter[$method]);
        if (!$validator->passes()) {
            throw new IllegalParameterException(sprintf('参数错误:[%s]', json_encode($validator->errors(), JSON_UNESCAPED_UNICODE)));
        }
        $http = $this->getHttp();
        $params['sign'] = $this->signature->getReqSign($params);
        $response = $files ? $http->upload($url, $params, $files) : $http->post($url, $params);
        $result = json_decode(strval($response->getBody()), true);
        if (isset($result['ret'])) {
            return $result;
        }

        return [
            'ret' => '-1',
            'msg' => sprintf('返回结果:[%s]', json_encode($result, JSON_UNESCAPED_UNICODE)),
        ];
    }