• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Requests类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Requests类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 <[email protected]>
  */
 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


示例16: applyAccessToken

 /**
  * 获得access_token
  * @return null
  */
 public function applyAccessToken($appid, $secret)
 {
     //        $redis = Redis::connection();
     //        if( ! $redis){
     //            throw new \Exception("redis connect error");
     //        }
     //        $accessToken = $redis->get('dajiayao.device.'.$appid);
     //        if( ! $accessToken){
     //            $url = sprintf(self::GET_TOKEN,$appid,$secret);
     //            $response = \Requests::get($url);
     //            $rtJson = $response->body;
     //            $rtJson = json_decode($rtJson);
     //            if (array_key_exists('access_token', $rtJson)) {
     //                $redis->setex('dajiayao.device.'.$appid,7000,$rtJson->access_token);
     //            }else{
     //                throw new \Exception("weixin get access_token error");
     //            }
     //        }
     //
     //        return $redis->get('dajiayao.device.'.$appid);
     //TODO 后期需要从缓存或者从access_token中央服务器中获取
     $url = sprintf(self::GET_TOKEN, $appid, $secret);
     $response = \Requests::get($url);
     $rtJson = $response->body;
     $rtJson = json_decode($rtJson);
     if (array_key_exists('access_token', $rtJson)) {
         return $rtJson->access_token;
     } else {
         throw new \Exception("weixin get access_token error");
     }
 }
开发者ID:hachi-zzq,项目名称:dajiayao,代码行数:35,代码来源:WeixinClient.php


示例17: heva_request

 /**
  * Envoie une requête à HEVA
  */
 public function heva_request($req_uri = "", $params = array())
 {
     $FFVV_Heva_Host = "api.licences.ffvv.stadline.com";
     $head = wsse_header_short($this->config->item('ffvv_id'), $this->config->item('ffvv_pwd'));
     $url = "http://" . $FFVV_Heva_Host . $req_uri;
     return Requests::get($url, array('X-WSSE' => $head), $params);
 }
开发者ID:flub78,项目名称:GVV3,代码行数:10,代码来源:FFVV.php


示例18: httpGetRequest

 public static function httpGetRequest($url)
 {
     Requests::register_autoloader();
     $headers = array('PAYDUNYA-PUBLIC-KEY' => Paydunya_Setup::getPublicKey(), 'PAYDUNYA-PRIVATE-KEY' => Paydunya_Setup::getPrivateKey(), 'PAYDUNYA-MASTER-KEY' => Paydunya_Setup::getMasterKey(), 'PAYDUNYA-TOKEN' => Paydunya_Setup::getToken(), 'PAYDUNYA-MODE' => Paydunya_Setup::getMode(), 'User-Agent' => "PAYDUNYA Checkout API PHP client v1 aka Neptune");
     $request = Requests::get($url, $headers, array('timeout' => 10));
     return json_decode($request->body, true);
 }
开发者ID:Katakeyni,项目名称:paydunya-php,代码行数:7,代码来源:utilities.php


示例19: checkVersion

 /**
  * Check Github for release information
  *
  * @return array
  */
 public function checkVersion()
 {
     // Prepare a return array
     $results = array('release_data' => null, 'versions_behind' => 0);
     // Get the current version
     $current_version = \Config::get('seat.version');
     try {
         // Check the releases from Github for eve-seat/seat
         $headers = array('Accept' => 'application/json');
         $request = \Requests::get('https://api.github.com/repos/eve-seat/seat/releases', $headers);
         if ($request->status_code == 200) {
             $results['release_data'] = json_decode($request->body);
             // Try and determine if we are up to date
             if ($results['release_data'][0]->tag_name == 'v' . $current_version) {
             } else {
                 foreach ($results['release_data'] as $release) {
                     if ($release->tag_name == 'v' . $current_version) {
                         break;
                     } else {
                         $results['versions_behind']++;
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $this->error('[!] Error: Failed to retrieve version information.');
         $this->error('[!] ' . $e->getMessage());
     }
     return $results;
 }
开发者ID:boweiliu,项目名称:seat,代码行数:35,代码来源:SeatUpdate.php


示例20: zipFile

 /**
  * Get the Zip File from Server & return back the downloaded file location
  */
 public static function zipFile($url, $zipFile)
 {
     if (!extension_loaded('zip')) {
         self::log("Dependency Missing, Please install PHP Zip Extension");
         echo ser("PHP Zip Extension", "I can't find the Zip PHP Extension. Please Install It & Try again");
     }
     self::log("Started Downloading Zip File from {$url} to {$zipFile}");
     $userAgent = 'LobbyBot/0.1 (' . L_SERVER . ')';
     /**
      * Get The Zip From Server
      */
     $hooks = new \Requests_Hooks();
     if (self::$progress != null) {
         $progress = self::$progress;
         $hooks->register('curl.before_send', function ($ch) use($progress) {
             curl_setopt($ch, CURLOPT_NOPROGRESS, false);
             curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, $progress);
         });
     }
     try {
         \Requests::get($url, array("User-Agent" => $userAgent), array('filename' => $zipFile, 'hooks' => $hooks, 'timeout' => time()));
     } catch (\Requests_Exception $error) {
         self::log("HTTP Requests Error ({$url}) : {$error}");
         echo ser("Error", "HTTP Requests Error : " . $error);
         return false;
     }
     self::log("Downloaded Zip File from {$url} to {$zipFile}");
     return $zipFile;
 }
开发者ID:LobbyOS,项目名称:server,代码行数:32,代码来源:Update.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP RequiredFields类代码示例发布时间:2022-05-23
下一篇:
PHP RequestUtil类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap