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


PHP Encoding::accept_encoding方法代码示例

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


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

示例1: request

 /**
  *
  * @param mixed $url
  * @param mixed $args
  * @return
  */
 private function request($url, $args)
 {
     $defaults = array('method' => 'GET', 'timeout' => 10, 'redirection' => 5, 'requested' => 0, 'httpversion' => 1.0, 'user-agent' => 'NUKEVIET CMS ' . $this->site_config['version'] . '. Developed by VINADES. Url: http://nukeviet.vn. Code: ' . md5($this->site_config['sitekey']), 'referer' => null, 'reject_unsafe_urls' => false, 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true, 'sslcertificates' => $this->root_dir . '/includes/certificates/ca-bundle.crt', 'stream' => false, 'filename' => null, 'limit_response_size' => null);
     // Get full args
     $args = $this->build_args($args, $defaults);
     // Get url info
     $infoURL = @parse_url($url);
     // Check valid url
     if (empty($url) or empty($infoURL['scheme'])) {
         $this->set_error(1);
         return false;
     }
     // Set SSL
     $args['ssl'] = $infoURL['scheme'] == 'https' or $infoURL['scheme'] == 'ssl';
     /**
      * Block url
      * By basic version, all url will be enabled and no blocking by check function
      */
     //if( $this->is_blocking( $url ) )
     //{
     //	$this->set_error(2);
     //	return false;
     //}
     // Determine if this request is to OUR install of NukeViet
     $homeURL = parse_url($this->site_config['my_domain']);
     $args['local'] = $homeURL['host'] == $infoURL['host'] || 'localhost' == $infoURL['host'];
     unset($homeURL);
     // If Stream but no file, default is a file in temp dir with base $url name
     if ($args['stream'] and empty($args['filename'])) {
         $args['filename'] = $this->tmp_dir . '/' . basename($url);
     }
     // Check if streaming a file
     if ($args['stream']) {
         $args['blocking'] = true;
         if (!@is_writable(dirname($args['filename']))) {
             $this->set_error(3);
             return false;
         }
     }
     // Default header is an empty array
     if (is_null($args['headers'])) {
         $args['headers'] = array();
     }
     if (!is_array($args['headers'])) {
         $processedHeaders = Http::processHeaders($args['headers'], $url);
         $args['headers'] = $processedHeaders['headers'];
     }
     // Get User Agent
     if (isset($args['headers']['User-Agent'])) {
         $args['user-agent'] = $args['headers']['User-Agent'];
         unset($args['headers']['User-Agent']);
     }
     if (isset($args['headers']['user-agent'])) {
         $args['user-agent'] = $args['headers']['user-agent'];
         unset($args['headers']['user-agent']);
     }
     // Get Referer
     if (isset($args['headers']['Referer'])) {
         $args['referer'] = $args['headers']['Referer'];
         unset($args['headers']['Referer']);
     } elseif (isset($args['headers']['referer'])) {
         $args['referer'] = $args['headers']['referer'];
         unset($args['headers']['referer']);
     }
     if ($args['httpversion'] == '1.1' and !isset($args['headers']['connection'])) {
         $args['headers']['connection'] = 'close';
     }
     Http::buildCookieHeader($args);
     Http::mbstring_binary_safe_encoding();
     if (!isset($args['headers']['Accept-Encoding'])) {
         if ($encoding = Encoding::accept_encoding($url, $args)) {
             $args['headers']['Accept-Encoding'] = $encoding;
         }
     }
     if (!is_null($args['body']) and '' != $args['body'] or $args['method'] == 'POST' or $args['method'] == 'PUT') {
         if (is_array($args['body']) or is_object($args['body'])) {
             $args['body'] = http_build_query($args['body'], null, '&');
             if (!isset($args['headers']['Content-Type'])) {
                 $args['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . $this->site_config['site_charset'];
             }
         }
         if ($args['body'] === '') {
             $args['body'] = null;
         }
         if (!isset($args['headers']['Content-Length']) and !isset($args['headers']['content-length'])) {
             $args['headers']['Content-Length'] = strlen($args['body']);
         }
     }
     $response = $this->_dispatch_request($url, $args);
     Http::reset_mbstring_encoding();
     if ($this->is_error($response)) {
         return $response;
     }
     // Append cookies that were used in this request to the response
//.........这里部分代码省略.........
开发者ID:NukeVietCMS,项目名称:CodeWeb,代码行数:101,代码来源:Http.php


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