本文整理汇总了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;
}
示例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;
}
示例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])) {
示例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;
}