本文整理汇总了PHP中Curl::makeRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Curl::makeRequest方法的具体用法?PHP Curl::makeRequest怎么用?PHP Curl::makeRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Curl
的用法示例。
在下文中一共展示了Curl::makeRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: consume
/**
* Consumes the resource by method and returns the results of the request.
*
* @param string $method Request method
* @param array $params Parameters
* @throws ResourceException If request method is not allowed
* @return array Request data
*/
public function consume($method, $params = array())
{
global $roster;
$makecache = false;
$msg = '';
if (!in_array($method, $this->methods_allowed)) {
$roster->set_message('The selected api action is not allowed', 'Method not allowed.', 'error');
//throw new ResourceException('Method not allowed.', 405);
}
// new prity url builder ... much better then befor...
$ui = API_URI;
//sprintf(self::API_URI, $this->region);
// new cache system see hwo old teh file is only live update files more then X days/hours old
$this->querytime = format_microtime();
$roster->db->query_count++;
$url = $this->url->BuildUrl($ui, $method, $params['server'], $params['name'], $params);
if ($method == 'auction') {
$data = $this->Curl->makeRequest($url, $params['type'], $params, $url, $method);
if ($this->Curl->errno !== CURLE_OK) {
throw new ResourceException($this->Curl->error, $this->Curl->errno);
}
$auction = json_decode($data['response'], true);
$url = $auction['files'][0]['url'];
}
$data = $this->Curl->makeRequest($url, null, $params, $url, $method);
if ($this->Curl->errno !== CURLE_OK) {
//throw new ResourceException($this->Curl->error, $this->Curl->errno);
$roster->set_message("The selected api action is not allowed <br/>\n\r [" . $this->Curl->errno . '] : ' . $this->Curl->error . '', 'Curl has Failed!', 'error');
}
$errornum = empty($data['response_headers']['http_code']) ? $data['response_headers']['http_code'] : '_911_';
//Battle.net returned a HTTP error code
$x = json_decode($data['response'], true);
//$makecache
if (isset($x['reason'])) {
$this->seterrors(array('type' => $method, 'msg' => $x['reason']));
$msg = $this->transhttpciode($data['response_headers']['http_code']);
$roster->set_message(' ' . $method . ': ' . $msg . ' : ' . $x['reason'] . '<br>' . $url . ' ', 'Api call fail!', 'error');
//$roster->set_message( ' '.$method.': '.$x['reason'].' ', 'Api call fail!', 'error' );
$this->query['result'] = false;
// over ride cache and set to false no data or no url no file lol
}
$roster->api2->cache->api_track($method, $url, $this->Curl->http_code, $this->Curl->content_type);
$this->usage = array('type' => $method, 'url' => $url, 'responce_code' => $this->Curl->http_code, 'content_type' => $this->Curl->content_type, 'locale' => $this->region);
if (method_exists($roster->api2->cache, 'insert' . $method) && is_callable(array($roster->api2->cache, 'insert' . $method))) {
call_user_func(array($roster->api2->cache, 'insert' . $method), $result, $this->usage, $params);
}
//print_r($data['response_headers']);
$data = json_decode($data['response'], true);
$info = $data;
//$this->utf8_array_decode($data);
return $info;
}
示例2: consume
/**
* Consumes the resource by method and returns the results of the request.
*
* @param string $method Request method
* @param array $params Parameters
* @throws ResourceException If request method is not allowed
* @return array Request data
*/
public function consume($method, $params = array())
{
if (!in_array($method, $this->methods_allowed) && !in_array('*', $this->methods_allowed)) {
throw new ResourceException('Method not allowed.', 405);
}
$data = $this->Curl->makeRequest($this->getResourceUri($method), 'GET', $params);
//cURL returned an error code
if ($this->Curl->errno !== CURLE_OK) {
throw new ResourceException($this->Curl->error, $this->Curl->errno);
}
//Battle.net returned a HTTP error code
if (!isset($data['response_headers']['http_code']) || $data['response_headers']['http_code'] !== 200) {
throw new HttpException(json_decode($data['response'], true), $data['response_headers']['http_code']);
}
return json_decode($data['response'], true);
}
示例3: consume
/**
* Consumes the resource by method and returns the results of the request.
*
* @param string $method Request method
* @param array $params Parameters
* @throws ResourceException If request method is not allowed
* @return array Request data
*/
public function consume($method, $params = array())
{
global $roster;
$makecache = false;
$msg = '';
if (!in_array($method, $this->methods_allowed)) {
$roster->set_message('The selected api action is not allowed', 'Method not allowed.', 'error');
//throw new ResourceException('Method not allowed.', 405);
}
// new prity url builder ... much better then befor...
$ui = API_URI;
//sprintf(self::API_URI, $this->region);
// new cache system see hwo old teh file is only live update files more then X days/hours old
$this->querytime = format_microtime();
$this->query_count++;
$url = $this->url->BuildUrl($ui, $method, $params['server'], $params['name'], $params);
if (isset($_GET['debug'])) {
echo '--[ ' . $url . ' ]--<br>';
}
$data = $this->Curl->makeRequest($url, null, $params, $url, $method);
if ($this->Curl->errno !== CURLE_OK) {
//throw new ResourceException($this->Curl->error, $this->Curl->errno);
$roster->set_message("The selected api action is not allowed <br/>\n\r [" . $this->Curl->errno . '] : ' . $this->Curl->error . '', 'Curl has Failed!', 'error');
}
$roster->db->queries['api/' . $method][$this->query_count]['query'] = $url;
$roster->db->queries['api/' . $method][$this->query_count]['time'] = round(format_microtime() - $this->querytime, 4);
$roster->db->queries['api/' . $method][$this->query_count]['line'] = '94';
$roster->db->queries['api/' . $method][$this->query_count]['error'] = empty($data['response_headers']['http_code']) ? $data['response_headers']['http_code'] : '';
// update the tracker...
$q = "SELECT * FROM `" . $roster->db->table('api_usage') . "` WHERE `date`='" . date("Y-m-d") . "' AND `type` = '" . $method . "'";
$y = $roster->db->query($q);
$row = $roster->db->fetch($y);
if (!isset($row['total'])) {
$query = 'INSERT INTO `' . $roster->db->table('api_usage') . '` VALUES ';
$query .= "('','" . $method . "','" . date("Y-m-d") . "','+1'); ";
} else {
$query = "Update `" . $roster->db->table('api_usage') . "` SET `total`='" . ($row['total'] + 1) . "' WHERE `type` = '" . $method . "' AND `date` = '" . date("Y-m-d") . "'";
}
$ret = $roster->db->query($query);
//Battle.net returned a HTTP error code
$x = json_decode($data['response'], true);
if (isset($data['response_headers']) && $data['response_headers']['http_code'] != '200') {
$msg = $this->transhttpciode($data['response_headers']['http_code']);
$roster->set_message(' ' . $method . ': ' . $msg . ' : ' . $x['reason'] . '<br>' . $url . ' ', 'Api call fail!', 'error');
// update the tracker...
/* this is not in the main roster install as of yet
$errornum = empty($data['response_headers']['http_code']) ? $data['response_headers']['http_code'] : '';
$q = "SELECT * FROM `" . $roster->db->table('api_error') . "` WHERE `error_info` = '".$params['name']."' AND `type` = '".$method."'";
$y = $roster->db->query($q);
$row = $roster->db->fetch($y);
if (!isset($row['total']))
{
$query = 'INSERT INTO `' . $roster->db->table('api_error') . '` VALUES ';
$query .= "('','".$method."','".$msg."','".$params['name']."','+1'); ";
}
else
{
$query = "Update `" . $roster->db->table('api_error') . "` SET `total`='".($row['total']+1)."' WHERE `type` = '".$method."' AND `error_info` = '".$params['name']."'";
}
$ret = $roster->db->query($query);
*/
//throw new HttpException(json_decode($data['response'], true), $data['response_headers']['http_code']);
//$this->seterrors(array('type'=>$method,'msg'=>''.$msg.'<br>'.$url.''));
//$this->query['result'] = false; // over ride cache and set to false no data or no url no file lol
}
//$makecache
if (isset($x['reason'])) {
$this->seterrors(array('type' => $method, 'msg' => $x['reason']));
$msg = $this->transhttpciode($data['response_headers']['http_code']);
$roster->set_message(' ' . $method . ': ' . $msg . ' : ' . $x['reason'] . '<br>' . $url . ' ', 'Api call fail!', 'error');
//$roster->set_message( ' '.$method.': '.$x['reason'].' ', 'Api call fail!', 'error' );
$this->query['result'] = false;
// over ride cache and set to false no data or no url no file lol
}
//print_r($data['response_headers']);
$data = json_decode($data['response'], true);
$info = $data;
//$this->utf8_array_decode($data);
return $info;
}