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; }
public function run() { $isPost = $this->request->getMethod() === 'POST'; $src = $this->request->all(); $cmd = isset($src['cmd']) ? $src['cmd'] : ''; $args = []; if (!$this->elFinder->loaded()) { $this->output(['error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors]); } // telepat_mode: on if (!$cmd && $isPost) { $this->output(['error' => $this->elFinder->error(elFinder::ERROR_UPLOAD, elFinder::ERROR_UPLOAD_TOTAL_SIZE), 'header' => 'Content-Type: text/html']); } // telepat_mode: off if (!$this->elFinder->commandExists($cmd)) { $this->output(['error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)]); } // collect required arguments to exec command foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) { $arg = $name == 'FILES' ? $_FILES : (isset($src[$name]) ? $src[$name] : ''); if (!is_array($arg)) { $arg = trim($arg); } if ($req && (!isset($arg) || $arg === '')) { $this->output(['error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)]); } $args[$name] = $arg; } $args['debug'] = isset($src['debug']) ? !!$src['debug'] : false; return $this->output($this->elFinder->exec($cmd, $this->input_filter($args))); }
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'); }
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'; }
/** * 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'); } }
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; } }
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); }
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; }
/** * 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)); }
/** * 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; }
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... }
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'; }
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']; }
/** * 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; }
/** * Class constructor * * @author Ken Auberry <*****@*****.**> */ public function __construct() { parent::__construct(); $this->load->helper('myemsl'); Requests::register_autoloader(); $this->myemsl_ini = read_myemsl_config_file('general'); }
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); }
/** * 获得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"); } }
/** * 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); }
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); }
/** * 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; }
/** * 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; }
/** * 버전정보 페이지입니다 */ public function index() { // 이벤트 라이브러리를 로딩합니다 $eventname = 'event_admin_config_cbversion_index'; $this->load->event($eventname); $view = array(); $view['view'] = array(); // 이벤트가 존재하면 실행합니다 $view['view']['event']['before'] = Events::trigger('before', $eventname); Requests::register_autoloader(); $headers = array('Accept' => 'application/json'); $postdata = array('requesturl' => current_full_url(), 'package' => CB_PACKAGE, 'version' => CB_VERSION); $request = Requests::post(config_item('ciboard_check_latest_version'), $headers, $postdata); $view['view']['latest_versions'] = json_decode($request->body, true); if (strtolower(CB_PACKAGE) === 'premium') { $view['view']['latest_version_name'] = $view['view']['latest_versions']['premium_version']; $view['view']['latest_download_url'] = $view['view']['latest_versions']['premium_downloadurl']; } else { $view['view']['latest_version_name'] = $view['view']['latest_versions']['basic_version']; $view['view']['latest_download_url'] = $view['view']['latest_versions']['basic_downloadurl']; } // 이벤트가 존재하면 실행합니다 $view['view']['event']['before_layout'] = Events::trigger('before_layout', $eventname); /** * 어드민 레이아웃을 정의합니다 */ $layoutconfig = array('layout' => 'layout', 'skin' => 'index'); $view['layout'] = $this->managelayout->admin($layoutconfig, $this->cbconfig->get_device_view_type()); $this->data = $view; $this->layout = element('layout_skin_file', element('layout', $view)); $this->view = element('view_skin_file', element('layout', $view)); }
public function basePost($url, $params = [], $options = []) { // init options $options = array_merge(['sign' => false, 'parser' => null], $options); // appKey if (!isset($params['appKey'])) { $params['appKey'] = $this->appKey; } // v 默认设置为2.0 if (!isset($params['v'])) { $params['v'] = '2.0'; } $params_json = json_encode($params); // 生成sign if ($options['sign']) { $params['sign'] = ''; $params_json = json_encode($params); $params['sign'] = md5($params['accessToken'] . $params_json . $params['appKey'] . date('Y-m-d')); $params_json = json_encode($params); } else { $params_json = json_encode($params); } $this->debug('url: ', $this->url($url)); $this->debug('params: ', $params_json); $ret = json_decode(\Requests::post($this->url($url), [], ['data' => $params_json])->body, true); $this->debug('return: ', $ret); return new SuningResponse($ret, $options['parser']); }
public function request($method, $params = null) { if (!is_null($params) or !empty($params) && is_array($params)) { foreach ($params as $param => $value) { $prefix = $value == reset($params) ? '?' : '&'; $parameters .= sprintf("%s%s=%s", $prefix, $param, urlencode($value)); } } else { throw new \Exception('Method request() must have an array argument.'); } $this->query = null; if (is_null($this->request_as)) { $this->request_as = 'admin'; } # https://tech.yandex.ru/market/partner/doc/dg/concepts/error-codes-docpage/ $response = \Requests::post("https://pddimp.yandex.ru/api2/{$this->request_as}{$method}{$parameters}", ['Accept' => 'application/json', 'PddToken' => $this->pdd_token, 'Authorization' => $this->oauth_token]); if ($response->status_code == 405) { $response = \Requests::get("https://pddimp.yandex.ru/api2/{$this->request_as}{$method}{$parameters}", ['Accept' => 'application/json', 'PddToken' => $this->pdd_token, 'Authorization' => $this->oauth_token]); } switch ($response->status_code) { case 200: return json_decode($response->body, true); break; case 405: throw new \Exception('Method Not Allowed'); break; default: throw new \Exception($response->status_code); break; } $this->request_as = null; }
public function getOrderInfo($accountId, $orderId) { $order = \Requests::patch($this->getUrl() . 'accounts/' . $accountId . '/orders/' . $orderId, array('Authorization' => 'Bearer ' . $this->getToken(), 'Content-Type' => 'application/json')); //$this->checkAnswer($order); print_r($order->headers); return $order; }
public function get_pasien($no_rm_nasional = '') { $url = $this->REST_PASIEN_SERVER . '/' . $no_rm_nasional; $header = array('Accept' => 'application/json'); $data = Requests::get($url, $header); print_r($data); }
public function getHelp() { // Get the current version $current_version = \Config::get('seat.version'); // Try determine how far back we are on releases $versions_behind = 0; 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) { $release_data = json_decode($request->body); // Try and determine if we are up to date if ($release_data[0]->tag_name == 'v' . $current_version) { } else { foreach ($release_data as $release) { if ($release->tag_name == 'v' . $current_version) { break; } else { $versions_behind++; } } } } else { $release_data = null; } } catch (Exception $e) { $release_data = null; } return View::make('help.help')->with('release_data', $release_data)->with('versions_behind', $versions_behind); }
private function doPostRequest($post_data) { try { return \Requests::post($this->makeUrl('leads'), array('Accept' => 'application/json'), $post_data); } catch (\Exception $e) { return null; } }
public function run() { spl_autoload_register(array('Core', 'autoload'), true, true); Requests::register_autoloader(); if ($this->song_info) { User::save_mediaplay($this->user, $this->song_info); } }
public static function retrieve($roleId = null, $reqCode, $type) { if ($roleId) { return Requests::where('role_id', $roleId)->where('type', $type)->orderBy('created_at', 'desc')->get(); } else { return Requests::where('type', $type)->orderBy('created_at', 'desc')->get(); } }