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


PHP RequestCore::set_useragent方法代码示例

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


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

示例1: getHttpResponse

 /**
  * @return array
  */
 protected function getHttpResponse($method, $url, $body, $headers)
 {
     $request = new RequestCore($url);
     foreach ($headers as $key => $value) {
         $request->add_header($key, $value);
     }
     $request->set_method($method);
     $request->set_useragent(USER_AGENT);
     if ($method == "POST") {
         $request->set_body($body);
     }
     $request->send_request();
     $response = array();
     $response[] = (int) $request->get_response_code();
     $response[] = $request->get_response_header();
     $response[] = $request->get_response_body();
     return $response;
 }
开发者ID:jesse108,项目名称:admin_base,代码行数:21,代码来源:Client.php

示例2: request

 /**
  * Method: request()
  * 	Requests the data, parses it, and returns it. Requires RequestCore and SimpleXML.
  *
  * Parameters:
  * 	url - _string_ (Required) The web service URL to request.
  *
  * Returns:
  * 	ResponseCore object
  */
 public function request($url)
 {
     if ($this->test_mode) {
         return $url;
     }
     // Generate cache filename
     $cache = $this->cache_path . get_class() . '_' . md5($url) . '.cache';
     // If cache exists, and is still valid, load it
     if ($this->cache_mode && file_exists($cache) && time() - filemtime($cache) < $this->cache_ttl) {
         $response = (object) json_decode(file_get_contents($cache));
         $response->_cached = true;
         // Add notice that this is a cached file
         return $response;
     }
     if (!class_exists('RequestCore')) {
         throw new Exception('This class requires RequestCore. http://requestcore.googlecode.com');
     }
     $http = new RequestCore($url);
     $http->set_useragent(LASTFM_USERAGENT);
     $http->send_request();
     $response = (object) $this->parse_response($http->get_response_body());
     if ($this->header_mode) {
         $response->_header = $http->get_response_header();
     }
     // Cache only successfuly requests
     if ($this->cache_mode && !isset($response->error)) {
         file_put_contents($cache . '_tmp', json_encode($response));
         rename($cache . '_tmp', $cache);
     }
     return $response;
 }
开发者ID:MusicalAPP,项目名称:lastfm,代码行数:41,代码来源:lastfmcache.class.php

示例3: auth


//.........这里部分代码省略.........
     $signable_list = array(self::OSS_PART_NUM, self::OSS_UPLOAD_ID);
     foreach ($signable_list as $item) {
         if (isset($options[$item])) {
             $signable_query_string_params[$item] = $options[$item];
         }
     }
     if ($this->enable_sts_in_url && !is_null($this->security_token)) {
         $signable_query_string_params["security-token"] = $this->security_token;
     }
     $signable_query_string = OSSUtil::to_query_string($signable_query_string_params);
     //合并 HTTP headers
     if (isset($options[self::OSS_HEADERS])) {
         $headers = array_merge($headers, $options[self::OSS_HEADERS]);
     }
     //生成请求URL
     $conjunction = '?';
     $non_signable_resource = '';
     if (isset($options[self::OSS_SUB_RESOURCE])) {
         $signable_resource .= $conjunction . $options[self::OSS_SUB_RESOURCE];
         $conjunction = '&';
     }
     if ($signable_query_string !== '') {
         $signable_query_string = $conjunction . $signable_query_string;
         $conjunction = '&';
     }
     if ($query_string !== '') {
         $non_signable_resource .= $conjunction . $query_string;
         $conjunction = '&';
     }
     $this->request_url = $scheme . $hostname . $signable_resource . $signable_query_string . $non_signable_resource;
     //创建请求
     $request = new RequestCore($this->request_url);
     $user_agent = OSS_NAME . "/" . OSS_VERSION . " (" . php_uname('s') . "/" . php_uname('r') . "/" . php_uname('m') . ";" . PHP_VERSION . ")";
     $request->set_useragent($user_agent);
     // Streaming uploads
     if (isset($options[self::OSS_FILE_UPLOAD])) {
         if (is_resource($options[self::OSS_FILE_UPLOAD])) {
             $length = null;
             if (isset($options[self::OSS_CONTENT_LENGTH])) {
                 $length = $options[self::OSS_CONTENT_LENGTH];
             } elseif (isset($options[self::OSS_SEEK_TO])) {
                 $stats = fstat($options[self::OSS_FILE_UPLOAD]);
                 if ($stats && $stats[self::OSS_SIZE] >= 0) {
                     $length = $stats[self::OSS_SIZE] - (int) $options[self::OSS_SEEK_TO];
                 }
             }
             $request->set_read_stream($options[self::OSS_FILE_UPLOAD], $length);
             if ($headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
                 $headers[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
             }
         } else {
             $request->set_read_file($options[self::OSS_FILE_UPLOAD]);
             $length = $request->read_stream_size;
             if (isset($options[self::OSS_CONTENT_LENGTH])) {
                 $length = $options[self::OSS_CONTENT_LENGTH];
             } elseif (isset($options[self::OSS_SEEK_TO]) && isset($length)) {
                 $length -= (int) $options[self::OSS_SEEK_TO];
             }
             $request->set_read_stream_size($length);
             if (isset($headers[self::OSS_CONTENT_TYPE]) && $headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
                 $mime_type = self::get_mime_type($options[self::OSS_FILE_UPLOAD]);
                 $headers[self::OSS_CONTENT_TYPE] = $mime_type;
             }
         }
     }
     if (isset($options[self::OSS_SEEK_TO])) {
开发者ID:codingoneapp,项目名称:codingone,代码行数:67,代码来源:sdk.class.php

示例4: request

 /**
  * Method: request()
  * 	Requests the data, parses it, and returns it. Requires RequestCore and SimpleXML.
  *
  * Parameters:
  * 	url - _string_ (Required) The web service URL to request.
  *
  * Returns:
  * 	ResponseCore object
  */
 public function request($url)
 {
     if (!$this->test_mode) {
         if (class_exists('RequestCore')) {
             $http = new RequestCore($url);
             $http->set_useragent(LASTFM_USERAGENT);
             $http->send_request();
             $response = new stdClass();
             $response->header = $http->get_response_header();
             $response->body = $this->parse_response($http->get_response_body());
             $response->status = $http->get_response_code();
             return $response;
         }
         throw new Exception('This class requires RequestCore. http://github.com/skyzyx/requestcore.');
     }
     return $url;
 }
开发者ID:MusicalAPP,项目名称:lastfm,代码行数:27,代码来源:lastfm.class.php


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