当前位置: 首页>>代码示例>>PHP>>正文


PHP Requests::flatten方法代码示例

本文整理汇总了PHP中Requests::flatten方法的典型用法代码示例。如果您正苦于以下问题:PHP Requests::flatten方法的具体用法?PHP Requests::flatten怎么用?PHP Requests::flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Requests的用法示例。


在下文中一共展示了Requests::flatten方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: request


//.........这里部分代码省略.........
             }
             $options['hooks']->dispatch('fsockopen.remote_host_path', array(&$path, $url));
             $out = $options['type'] . " {$path} HTTP/1.0\r\n";
             if (is_array($data)) {
                 $request_body = http_build_query($data, null, '&');
             } else {
                 $request_body = $data;
             }
             if (empty($headers['Content-Length'])) {
                 $headers['Content-Length'] = strlen($request_body);
             }
             if (empty($headers['Content-Type'])) {
                 $headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
             }
             break;
         case Requests::HEAD:
         case Requests::GET:
         case Requests::DELETE:
             $path = self::format_get($url_parts, $data);
             $options['hooks']->dispatch('fsockopen.remote_host_path', array(&$path, $url));
             $out = $options['type'] . " {$path} HTTP/1.0\r\n";
             break;
     }
     $out .= "Host: {$url_parts['host']}";
     if ($url_parts['port'] !== 80) {
         $out .= ":{$url_parts['port']}";
     }
     $out .= "\r\n";
     $out .= "User-Agent: {$options['useragent']}\r\n";
     $accept_encoding = $this->accept_encoding();
     if (!empty($accept_encoding)) {
         $out .= "Accept-Encoding: {$accept_encoding}\r\n";
     }
     $headers = Requests::flatten($headers);
     if (!empty($headers)) {
         $out .= implode($headers, "\r\n") . "\r\n";
     }
     $options['hooks']->dispatch('fsockopen.after_headers', array(&$out));
     if (substr($out, -2) !== "\r\n") {
         $out .= "\r\n";
     }
     $out .= "Connection: Close\r\n\r\n" . $request_body;
     $options['hooks']->dispatch('fsockopen.before_send', array(&$out));
     fwrite($fp, $out);
     $options['hooks']->dispatch('fsockopen.after_send', array(&$fake_headers));
     if (!$options['blocking']) {
         fclose($fp);
         $fake_headers = '';
         $options['hooks']->dispatch('fsockopen.after_request', array(&$fake_headers));
         return '';
     }
     $timeout_sec = (int) floor($options['timeout']);
     $timeout_msec = $timeout_sec == $options['timeout'] ? 0 : self::SECOND_IN_MICROSECONDS * $options['timeout'] % self::SECOND_IN_MICROSECONDS;
     stream_set_timeout($fp, $timeout_sec, $timeout_msec);
     $response = $body = $headers = '';
     $this->info = stream_get_meta_data($fp);
     $size = 0;
     $doingbody = false;
     $download = false;
     if ($options['filename']) {
         $download = fopen($options['filename'], 'wb');
     }
     while (!feof($fp)) {
         $this->info = stream_get_meta_data($fp);
         if ($this->info['timed_out']) {
             throw new Requests_Exception('fsocket timed out', 'timeout');
开发者ID:haipham,项目名称:Requests,代码行数:67,代码来源:fsockopen.php

示例2: setup_handle

 /**
  * Setup the cURL handle for the given data
  *
  * @param string $url URL to request
  * @param array $headers Associative array of request headers
  * @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
  * @param array $options Request options, see {@see Requests::response()} for documentation
  */
 protected function setup_handle($url, $headers, $data, $options)
 {
     $options['hooks']->dispatch('curl.before_request', array(&$this->handle));
     // Force closing the connection for old versions of cURL (<7.22).
     if (!isset($headers['Connection'])) {
         $headers['Connection'] = 'close';
     }
     $headers = Requests::flatten($headers);
     if (!empty($data)) {
         $data_format = $options['data_format'];
         if ($data_format === 'query') {
             $url = self::format_get($url, $data);
             $data = '';
         } elseif (!is_string($data)) {
             $data = http_build_query($data, null, '&');
         }
     }
     switch ($options['type']) {
         case Requests::POST:
             curl_setopt($this->handle, CURLOPT_POST, true);
             curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
             break;
         case Requests::HEAD:
             curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
             curl_setopt($this->handle, CURLOPT_NOBODY, true);
             break;
         case Requests::TRACE:
             curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
             break;
         case Requests::PATCH:
         case Requests::PUT:
         case Requests::DELETE:
         case Requests::OPTIONS:
         default:
             curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
             if (!empty($data)) {
                 curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
             }
     }
     // cURL requires a minimum timeout of 1 second when using the system
     // DNS resolver, as it uses `alarm()`, which is second resolution only.
     // There's no way to detect which DNS resolver is being used from our
     // end, so we need to round up regardless of the supplied timeout.
     //
     // https://github.com/curl/curl/blob/4f45240bc84a9aa648c8f7243be7b79e9f9323a5/lib/hostip.c#L606-L609
     $timeout = max($options['timeout'], 1);
     if (is_int($timeout) || $this->version < self::CURL_7_16_2) {
         curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout));
     } else {
         curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000));
     }
     if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) {
         curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout']));
     } else {
         curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000));
     }
     curl_setopt($this->handle, CURLOPT_URL, $url);
     curl_setopt($this->handle, CURLOPT_REFERER, $url);
     curl_setopt($this->handle, CURLOPT_USERAGENT, $options['useragent']);
     curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
     if ($options['protocol_version'] === 1.1) {
         curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     } else {
         curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
     }
     if (true === $options['blocking']) {
         curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
         curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
         curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
     }
 }
开发者ID:Garth619,项目名称:Femi9,代码行数:79,代码来源:cURL.php

示例3: setup_handle

 /**
  * Setup the cURL handle for the given data
  *
  * @param string $url URL to request
  * @param array $headers Associative array of request headers
  * @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
  * @param array $options Request options, see {@see Requests::response()} for documentation
  */
 protected function setup_handle($url, $headers, $data, $options)
 {
     $options['hooks']->dispatch('curl.before_request', array(&$this->fp));
     $headers = Requests::flatten($headers);
     if (in_array($options['type'], array(Requests::HEAD, Requests::GET, Requests::DELETE)) & !empty($data)) {
         $url = self::format_get($url, $data);
     } elseif (!empty($data) && !is_string($data)) {
         $data = http_build_query($data, null, '&');
     }
     switch ($options['type']) {
         case Requests::POST:
             curl_setopt($this->fp, CURLOPT_POST, true);
             curl_setopt($this->fp, CURLOPT_POSTFIELDS, $data);
             break;
         case Requests::PATCH:
         case Requests::PUT:
             curl_setopt($this->fp, CURLOPT_CUSTOMREQUEST, $options['type']);
             curl_setopt($this->fp, CURLOPT_POSTFIELDS, $data);
             break;
         case Requests::DELETE:
             curl_setopt($this->fp, CURLOPT_CUSTOMREQUEST, 'DELETE');
             break;
         case Requests::HEAD:
             curl_setopt($this->fp, CURLOPT_NOBODY, true);
             break;
     }
     if (is_int($options['timeout']) or $this->version < self::CURL_7_16_2) {
         curl_setopt($this->fp, CURLOPT_TIMEOUT, ceil($options['timeout']));
     } else {
         curl_setopt($this->fp, CURLOPT_TIMEOUT_MS, round($options['timeout'] * 1000));
     }
     if (is_int($options['connect_timeout']) or $this->version < self::CURL_7_16_2) {
         curl_setopt($this->fp, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout']));
     } else {
         curl_setopt($this->fp, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000));
     }
     curl_setopt($this->fp, CURLOPT_URL, $url);
     curl_setopt($this->fp, CURLOPT_REFERER, $url);
     curl_setopt($this->fp, CURLOPT_USERAGENT, $options['useragent']);
     curl_setopt($this->fp, CURLOPT_HTTPHEADER, $headers);
     if (true === $options['blocking']) {
         curl_setopt($this->fp, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
         curl_setopt($this->fp, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
         curl_setopt($this->fp, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
     }
 }
开发者ID:Steadroy,项目名称:YOURLS,代码行数:54,代码来源:cURL.php

示例4: setup_handle

 /**
  * Setup the cURL handle for the given data
  *
  * @param string $url URL to request
  * @param array $headers Associative array of request headers
  * @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
  * @param array $options Request options, see {@see Requests::response()} for documentation
  */
 protected function setup_handle($url, $headers, $data, $options)
 {
     $options['hooks']->dispatch('curl.before_request', array(&$this->handle));
     // Force closing the connection for old versions of cURL (<7.22).
     if (!isset($headers['Connection'])) {
         $headers['Connection'] = 'close';
     }
     $headers = Requests::flatten($headers);
     if (!empty($data)) {
         $data_format = $options['data_format'];
         if ($data_format === 'query') {
             $url = self::format_get($url, $data);
             $data = '';
         } elseif (!is_string($data)) {
             $data = http_build_query($data, null, '&');
         }
     }
     switch ($options['type']) {
         case Requests::POST:
             curl_setopt($this->handle, CURLOPT_POST, true);
             curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
             break;
         case Requests::PATCH:
         case Requests::PUT:
         case Requests::DELETE:
         case Requests::OPTIONS:
             curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
             curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
             break;
         case Requests::HEAD:
             curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
             curl_setopt($this->handle, CURLOPT_NOBODY, true);
             break;
         case Requests::TRACE:
             curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
             break;
     }
     if (is_int($options['timeout']) || $this->version < self::CURL_7_16_2) {
         curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($options['timeout']));
     } else {
         curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($options['timeout'] * 1000));
     }
     if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) {
         curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout']));
     } else {
         curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000));
     }
     curl_setopt($this->handle, CURLOPT_URL, $url);
     curl_setopt($this->handle, CURLOPT_REFERER, $url);
     curl_setopt($this->handle, CURLOPT_USERAGENT, $options['useragent']);
     curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
     if ($options['protocol_version'] === 1.1) {
         curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     } else {
         curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
     }
     if (true === $options['blocking']) {
         curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
         curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
         curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
     }
 }
开发者ID:BoldGrid,项目名称:WordPress,代码行数:70,代码来源:cURL.php


注:本文中的Requests::flatten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。