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


PHP Requests类代码示例

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


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

示例1: SingleRequest

 public static function SingleRequest($url, $data = false, $type = "GET", $extra_options = false)
 {
     $response = false;
     if ($type === "GET" && $data !== false) {
         $query = http_build_query($data);
         if (strpos($url, "?")) {
             $url = "{$url}&{$query}";
         } else {
             $url = "{$url}?{$query}";
         }
         $data = false;
     }
     $options = ['url' => $url, "post_data" => $data, "callback" => function (Response $result) use(&$response) {
         $response = $result;
     }];
     if (is_array($extra_options)) {
         foreach ($extra_options as $key => $val) {
             $options[$key] = $val;
         }
     }
     $http = new Requests();
     $http->addRequest($options, false);
     $http->execute();
     return $response;
 }
开发者ID:stevecoug,项目名称:cohort,代码行数:25,代码来源:Requests.php

示例2: store

 public function store(Requests $request)
 {
     //este metodo recebe os parametros passasdos pelo formulario
     //vamos pegar todos os parametros e armarzenar no banco de dados
     User::create($request->all());
     //armazena a mensagem
     Flash::message("Produto adicionado com sucesso!");
     //e em seguida redirecionar o usuario para a pagina com a lista dos produtos cadastrados
     return redirect()->action('UserController@listar');
 }
开发者ID:Brendow007,项目名称:meuprojeto,代码行数:10,代码来源:UserController.php

示例3: action_twfc

function action_twfc()
{
    global $post, $wpdb;
    // incluir o arquivo que trata
    // as requisições do formulario
    require_once TWFC_PATH . DS . 'requests.php';
    $form = new Requests();
    $form->varPost();
    // incluir o arquivo com o formulario
    require_once VIEWS_PATH . 'default.php';
}
开发者ID:reinaldorodrigues,项目名称:twfc-post,代码行数:11,代码来源:twfc-post.php

示例4: getDepartures

 /**
  * Gets departures from the given station starting at the given time.
  *
  * @param int $stationID
  * @param Carbon $time
  * @return array
  * @throws ApiException
  */
 public static function getDepartures(int $stationID, Carbon $time, int $maxJourneys = 10)
 {
     // prepare parameters for our request
     $query = ['input' => $stationID, 'boardType' => 'dep', 'time' => $time->format('H:i'), 'date' => $time->format('d.m.y'), 'maxJourneys' => $maxJourneys, 'start' => 'yes'];
     // send it to the bvg mobile site
     $response = \Requests::get(self::getApiEndpoint() . '?' . http_build_query($query));
     if ($response->status_code == 200) {
         // our results array
         $departures = [];
         // prepare document
         $dom = new Dom();
         $dom->load($response->body);
         // get date from API
         $date = $dom->find('#ivu_overview_input');
         $date = trim(substr($date->text, strpos($date->text, ':') + 1));
         $date = Carbon::createFromFormat('d.m.y', $date, 'Europe/Berlin');
         // get table data without the first line (header)
         $rows = $dom->find('.ivu_result_box .ivu_table tbody tr');
         // loop through each departure in the table
         foreach ($rows as $row) {
             // get columns
             $columns = $row->find('td');
             // explode time into two parts
             $time = explode(':', strip_tags($columns[0]));
             // push the departure onto our results array
             $departures[] = ['time' => $date->copy()->hour($time[0])->minute($time[1])->second(0), 'line' => trim(strip_tags($columns[1]->find('a')[0])), 'direction' => trim(strip_tags($columns[2]))];
         }
         // return results
         return $departures;
     } else {
         throw new ApiException('Failed getting station data from BVG API');
     }
 }
开发者ID:mkerix,项目名称:php-bvg,代码行数:41,代码来源:Station.php

示例5: send

 static function send($url, $headers = [], $options = [], $set = ['ret' => 'body', 'post' => ''])
 {
     $default_headers = ['User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36'];
     $default_options = ['follow_redirects' => false, 'timeout' => 30];
     $headers = $headers + $default_headers;
     $options = $options + $default_options;
     //出错的话就访问10次
     for ($i = 1; $i < 10; $i++) {
         \Log::debug("第{$i}次访问" . $url);
         try {
             if (isset($set['post']) && $set['post'] != "") {
                 $html = \Requests::post($url, $headers, $set['post'], $options);
             } else {
                 $html = \Requests::get($url, $headers, $options);
             }
         } catch (\Requests_Exception $e) {
             continue;
             //表示url访问出错了
         }
         if ($html->body != "") {
             break;
         }
         //表示访问正确
     }
     if ($set['ret'] == 'body') {
         return $html->body;
     } else {
         return $html;
     }
 }
开发者ID:wangtongphp,项目名称:weixin-stat,代码行数:30,代码来源:CURL.php

示例6: query_lastfm

 public static function query_lastfm($url)
 {
     debug_event('Recommendation', 'search url : ' . $url, 5);
     $request = Requests::get($url, array(), Core::requests_options());
     $content = $request->body;
     return simplexml_load_string($content);
 }
开发者ID:bl00m,项目名称:ampache,代码行数:7,代码来源:recommendation.class.php

示例7: request

 public function request($request_type = 'post', $url = '', $data = array(), $headers = array())
 {
     $options = $this->_options;
     $res = ['status' => -1, 'res' => []];
     try {
         switch ($request_type) {
             case 'post':
                 $response = Requests::post($url, $headers, $data, $options);
                 break;
             case 'get':
                 $response = Requests::request($url, $headers, $data, Requests::GET, $options);
                 break;
             default:
                 $response = Requests::post($url, $headers, $data, $options);
                 break;
         }
         if ($response->status_code == 200) {
             $res = ['status' => 0, 'msg' => 'success', 'res' => trim($response->body)];
         } else {
             $res = ['status' => -1, 'msg' => 'fail', 'res' => trim($response->body)];
         }
     } catch (Exception $e) {
         $res = ['status' => -1, 'msg' => $e->getMessage(), 'res' => ''];
     }
     return $res;
 }
开发者ID:xiaoziwuzui,项目名称:gdby_github_repo,代码行数:26,代码来源:dachu_request.php

示例8: getAccount

 /**
  * Get account information
  * 
  * @param Int $id - Account ID
  * @return \Oanda\response\getAccount\AccountFull
  */
 public function getAccount($id)
 {
     $headers = array('Authorization' => 'Bearer ' . $this->getToken());
     $response = \Requests::get($this->getUrl() . '/accounts/' . $id, $headers);
     $this->checkAnswer($response);
     return new \Oanda\response\getAccount\AccountFull(json_decode($response->body));
 }
开发者ID:nikopeikrishvili,项目名称:oanda,代码行数:13,代码来源:Account.php

示例9: process_request

 /**
  * Process Netki API request and response
  *
  * @param string $partnerId
  * @param string $apiKey
  * @param string $apiURL
  * @param string $method
  * @param array $data
  * @return array|mixed
  * @throws \Exception
  */
 public function process_request($partnerId, $apiKey, $apiURL, $method, $data)
 {
     $supportedMethods = array('GET', 'PUT', 'POST', 'DELETE');
     $successCodes = array(200, 201, 202, 204);
     if (!in_array($method, $supportedMethods)) {
         throw new \Exception('Unsupported method: ' . $method);
     }
     $headers = array('content-type' => 'application/json', 'X-Partner-ID' => $partnerId, 'Authorization' => $apiKey);
     $postData = !empty($data) ? json_encode($data) : null;
     $response = \Requests::request($apiURL, $headers, $postData, $method);
     if ($method == 'DELETE' && $response->status_code == 204) {
         return array();
     }
     $responseData = json_decode($response->body);
     if (empty($responseData)) {
         throw new \Exception('Error parsing JSON Data');
     }
     if (!$responseData->success || !in_array($response->status_code, $successCodes)) {
         $errorMessage = $responseData->message;
         if (isset($responseData->failures)) {
             $errorMessage .= ' [FAILURES: ';
             $failures = array();
             foreach ($responseData->failures as $failure) {
                 array_push($failures, $failure->message);
             }
             $errorMessage .= join(', ', $failures) . ']';
         }
         throw new \Exception('Request Failed: ' . $errorMessage);
     }
     return $responseData;
 }
开发者ID:netkicorp,项目名称:php-partner-api-client,代码行数:42,代码来源:Request.php

示例10: closeSpace

 private function closeSpace()
 {
     $data = array('key' => '', 'state' => 0, 'message' => 'opened by HackerBar', 'submit' => "Open the space");
     $response = Requests::post('http://awesomespace.nl/state/index.php', array(), $data);
     return $response->body;
     // ignore the response body... since we are slackers...
 }
开发者ID:stitch,项目名称:HackerBar,代码行数:7,代码来源:spacestate.php

示例11: __construct

 function __construct()
 {
     parent::__construct();
     $this->load->library(array('tank_auth', 'form_validation'));
     $this->user = $this->tank_auth->get_user_id();
     $this->username = $this->tank_auth->get_username();
     // Set username
     if (!$this->user) {
         $this->session->set_flashdata('response_status', 'error');
         $this->session->set_flashdata('message', lang('access_denied'));
         redirect('auth/login');
     }
     Requests::register_autoloader();
     $this->auth_key = config_item('api_key');
     // Set our API KEY
     $this->load->module('layouts');
     $this->load->config('rest');
     $this->load->library('template');
     $this->template->title(lang('settings') . ' - ' . config_item('company_name') . ' ' . config_item('version'));
     $this->page = lang('settings');
     $this->load->model('settings_model', 'settings');
     $this->general_setting = '?settings=general';
     $this->invoice_setting = '?settings=invoice';
     $this->system_setting = '?settings=system';
 }
开发者ID:vincenttaglia,项目名称:freelancer-office-bitcoin-payment,代码行数:25,代码来源:settings.php

示例12: getFavForums

 public function getFavForums()
 {
     $data = array('tbs' => $this->getTbs());
     $response = Requests::get(self::FAV_URL . "?" . $this->encrypt($data), $this->_headers);
     $response = (array) json_decode($response->body);
     return $response['forum_list'];
 }
开发者ID:friparia,项目名称:tieba,代码行数:7,代码来源:Tieba.class.php

示例13: get

 /**
  * post a GET request.
  */
 protected function get($method, $params = array(), $headers = array(), $options = array())
 {
     # construct the query URL.
     $url = self::HOST_API_URL . $method;
     $auth_head = $this->get_auth_header($this->access_key, $this->secret_key);
     if (!$headers) {
         $headers = array();
     }
     if (!$options) {
         $options = array();
     }
     // set timeout
     $options['timeout'] = 10 * 60;
     $headers['Authorization'] = $auth_head;
     // build query url.
     $url = $this->build_http_parameters($url, $params);
     // echo "$url";
     $response = Requests::get($url, $headers, $params, $options);
     // echo $response->body;
     # Handle any HTTP errors.
     if ($response->status_code != 200) {
         throw new ViSearchException("HTTP failure, status code {$response->status_code}");
     }
     # get the response as an object.
     $response_json = json_decode($response->body);
     return $response_json;
 }
开发者ID:bo-git,项目名称:visearch-sdk-php,代码行数:30,代码来源:base_request.php

示例14: __construct

 /**
  *  Class constructor
  *
  *  @author Ken Auberry <kenneth.auberry@pnnl.gov>
  */
 public function __construct()
 {
     parent::__construct();
     $this->load->helper('myemsl');
     Requests::register_autoloader();
     $this->myemsl_ini = read_myemsl_config_file('general');
 }
开发者ID:EMSL-MSC,项目名称:pacifica-upload-status,代码行数:12,代码来源:Myemsl_model.php

示例15: httpGetRequest

 public static function httpGetRequest($url)
 {
     Requests::register_autoloader();
     $headers = array('MP-Public-Key' => MPower_Setup::getPublicKey(), 'MP-Private-Key' => MPower_Setup::getPrivateKey(), 'MP-Master-Key' => MPower_Setup::getMasterKey(), 'MP-Token' => MPower_Setup::getToken(), 'MP-Mode' => MPower_Setup::getMode(), 'User-Agent' => "MPower Checkout API PHP client v1 aka Don Nigalon");
     $request = Requests::get($url, $headers, array('timeout' => 10));
     return json_decode($request->body, true);
 }
开发者ID:votomobile,项目名称:mpower_php,代码行数:7,代码来源:utilities.php


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