public static function httpPostRequest($url, $data = array()) { Requests::register_autoloader(); $headers = array('Accept' => 'application/x-www-form-urlencoded', '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::post($url, $headers, $data, array('timeout' => 10)); return json_decode($request->body, true); }
/** * post a post request. */ protected function post($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; // echo "$url"; $response = Requests::post($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; }
/** * Check Domain Availibility * Check the domain availibility and the current price or the new appened price * * @var string $keyword * @return array $domains * @author rama@networks.co.id */ public function checkDomain($keyword) { $post = array('keyword' => $keyword, 'tlds' => array('com', 'org', 'me'), 'services' => array('availability')); $request = Requests::post($this->url . '/api/domain/check', array(), json_encode($post)); $data = json_decode($request->body, TRUE); return array_map(array($this, "__processPrice"), $data['domains']); }
/** * Searches for station data using a search term. * * @param string $searchTerm * @return array * @throws ApiException */ public static function getStations(string $searchTerm) { // send search data to bvg mobile site $payload = ['input' => $searchTerm]; $response = \Requests::post(self::getApiEndpoint(), [], $payload); if ($response->status_code == 200) { // our results array $stations = []; // prepare document $dom = new Dom(); $dom->load($response->body); // loop through each suggested station foreach ($dom->find('.select a') as $station) { // get url parameters of current station for info $url = html_entity_decode($station->href); $query = parse_url($url)['query']; parse_str($query, $parameters); // push the station information onto our results array $stations[] = ['id' => $parameters['input'], 'name' => trim($station->text)]; } // return results return $stations; } else { throw new ApiException('Failed getting station data from BVG API'); } }
/** * Create new order * * @param type $instrument * @param type $units * @param type $side * @param type $type * @param type $expire * @param type $price * @param type $lowerBound * @param type $upperBound * @param type $stopLoss * @param type $takeProfit * @param type $trailingStop * @return type */ public function openOrder($accountId, $instrument, $units, $side, $type, $expire = false, $price = false, $lowerBound = false, $upperBound = false, $stopLoss = false, $takeProfit = false, $trailingStop = false) { $headers = array('Authorization' => 'Bearer ' . $this->getToken()); $data = array(); $data['instrument'] = $instrument; $data['units'] = $units; $data['side'] = $side; $data['type'] = $type; $data['expire'] = $expire; $data['price'] = $price; $data['lowerBound'] = $lowerBound; $data['upperBound'] = $upperBound; $data['stopLoss'] = $stopLoss; $data['takeProfit'] = $takeProfit; $data['trailingStop'] = $trailingStop; foreach ($data as &$d) { print_r($d); if (!$d) { unset($d); } } $response = \Requests::post($this->getUrl() . '/accounts/' . $accountId . '/orders', $headers, $data); $this->checkAnswer($response); return $response; }
public static function httpPostRequest($url, $data = array()) { Requests::register_autoloader(); $headers = array('Accept' => 'application/x-www-form-urlencoded', '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::post($url, $headers, $data, array('timeout' => 10)); return json_decode($request->body, true); }
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 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; }
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']); }
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... }
/** * 버전정보 페이지입니다 */ 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)); }
/** * @param $data_string * @param $url * @param $options * @return mixed */ protected function doPost($url, $data_string, $options = []) { $headers = array('Content-Type' => 'application/json'); $options['timeout'] = 600; $response = \Requests::post($url, $headers, $data_string, $options); return json_decode($response->body); }
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 kirim_pasien($mpas_id = '', $mrs_id = '', $tkunj_norm = '') { $headers = array('Accept' => 'application/json'); $url = 'http://localhost/semar_server/index.php/api/pasien/save_pasien'; $data = array('mpas_id' => $mpas_id, 'mrs_id' => $mrs_id, 'tkunj_no_rm' => $tkunj_norm); $status = Requests::post($url, $headers, $data); // print_r($status); }
public function testPOSTWithArray() { $data = array('test' => 'true', 'test2' => 'test'); $request = Requests::post('http://httpbin.org/post', array(), $data, $this->getOptions()); $this->assertEquals(200, $request->status_code); $result = json_decode($request->body, true); $this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['form']); }
/** * @param Message $message * * @return bool */ public function send(Message $message) { $headers = array(); $post_data = array('auth' => $this->auth_token, 'originator' => $message->getFrom(), 'destination' => $message->getTo(), 'message' => $message->getMessage()); $http_response = \Requests::post(self::API_ENDPOINT, $headers, $post_data); $gradwell_response = new Response($http_response->body); return $http_response->success && $gradwell_response->isSuccessful(); }
public function delete($files, $delfolders = 0) { $post = array('token' => $this->token, '_METHOD' => 'DELETE', 'delfolders' => $delfolders); $post['files'] = json_encode($files); $headers = array('Content-type' => 'multipart/form-data'); $request = Requests::post($this->url_service, array(), $post); echo $request->body; }
private function doPostRequest($post_data) { try { return \Requests::post($this->makeUrl('leads'), array('Accept' => 'application/json'), $post_data); } catch (\Exception $e) { return null; } }
public static function post($url, array $data) { $response = \Requests::post($url, array(), $data); if ($response->success) { return json_decode($response->body, true); } return false; }
function get_tour_info($tour_id) { $apiurl = hostname . "api/xml/tours/tour_info"; $params['tour_id'] = $tour_id; $payload = file_get_contents("buyer.xml"); // Now let's make a request! $request = Requests::post($apiurl . "?" . http_build_query($params), array(), array('__payload__' => $payload)); return simplexml_load_string($request->body); }
public function login() { /* * Usermodels to initiate your core functionality */ $login_result = UserModel::login(Requests::post('username'), Requests::post('password')); //render the page views to show the html,css,js etc $views->page('user/login'); }
function generate() { $url = $this->_url('/v1/documents.json'); $data = json_encode($this->data); $request = \Requests::post($url, $this->_prepareHeaders(), $data); if ($request->body) { $this->response = json_decode($request->body, true); } return $this; }
public function request($method, $url, $api_key, $data = NULL, $headers = array("Content-Type" => "application/json", "Accept" => "application/json")) { try { $options = array('auth' => new \Requests_Auth_Basic(array($api_key, ''))); if ($method == "GET") { $url_params = is_array($data) ? '?' . http_build_query($data) : ''; $response = \Requests::get(Client::BASE_URL . $url . $url_params, $headers, $options); } else { if ($method == "POST") { $response = \Requests::post(Client::BASE_URL . $url, $headers, json_encode($data), $options); } else { if ($method == "PATCH") { $response = \Requests::patch(Client::BASE_URL . $url, $headers, json_encode($data), $options); } else { if ($method == "DELETE") { $response = \Requests::delete(Client::BASE_URL . $url, $headers, $options); } } } } } catch (\Exception $e) { throw new UnableToConnect(); } if ($response->status_code >= 200 && $response->status_code <= 206) { if ($method == "DELETE") { return $response->status_code == 204 || $response->status_code == 200; } return json_decode($response->body); } if ($response->status_code == 400) { $code = 0; $message = ""; try { $error = (array) json_decode($response->body)->errors[0]; $code = key($error); $message = current($error); } catch (\Exception $e) { throw new UnhandledError($response->body, $response->status_code); } throw new InputValidationError($message, $code); } if ($response->status_code == 401) { throw new AuthenticationError(); } if ($response->status_code == 404) { throw new NotFound(); } if ($response->status_code == 403) { throw new InvalidApiKey(); } if ($response->status_code == 405) { throw new MethodNotAllowed(); } throw new UnhandledError($response->body, $response->status_code); }
public static function sendRequest($url, $options = array(), $access_token = NULL) { $full_url = self::MONEY_URL . $url; if ($access_token != NULL) { $headers = array("Authorization" => sprintf("Bearer %s", $access_token)); } else { $headers = array(); } $result = \Requests::post($full_url, $headers, $options); return self::processResult($result); }
public function hitBniEcollection($request) { $host = $this->getMode() == 'production' ? getenv('URL_API_BNI_ECOLLECTION_PRODUCTION') : getenv('URL_API_BNI_ECOLLECTION_DEVELOPMENT'); Ngeping::host($host); $headers = array('Content-Type' => 'application/json'); $options = array('timeout' => 15); $sendRequest = \Requests::post($host, $headers, $request, $options); if ($sendRequest->status_code != 200) { throw new BillingException('Status HTTP Code ' . $sendRequest->status_code); } return $sendRequest->body; }
/** * @dataProvider transportProvider */ public function testPOSTUsingInstantiation($transport) { $options = array('auth' => new Requests_Auth_Basic(array('user', 'passwd')), 'transport' => $transport); $data = 'test'; $request = Requests::post('http://httpbin.org/post', array(), $data, $options); $this->assertEquals(200, $request->status_code); $result = json_decode($request->body); $auth = $result->headers->Authorization; $auth = explode(' ', $auth); $this->assertEquals(base64_encode('user:passwd'), $auth[1]); $this->assertEquals('test', $result->data); }
/** * 获取post方法的返回值 * * @param $url * @param $cacert * @param $para * @param string $input_charset * * @return string */ public static function getHttpResponse($method, $url, $cacert, $para, $input_charset = '') { if (trim($input_charset) != '') { $url = $url . "_input_charset=" . $input_charset; } if ($method == 'post') { $result = \Requests::post($url, array(), $para, array('verify' => $cacert)); } else { $result = \Requests::get($url, array(), array('verify' => $cacert)); } Logger::addInfo('alipay_wap_submit', 'getHttpResponse', array('method' => $method, 'url' => $url, 'cacert' => $cacert, 'para' => $para, 'result' => $result->body)); return $result->body; }
public function call($path, array $params = null) { $url = $this->_config->getItem('url', false); $headers = ['X-Opsview-Username' => $this->_username, 'X-Opsview-Token' => $this->_token, 'accept' => 'application/json']; if (substr($url, -1, 1) !== '/') { $url = $url . '/'; } if ($params === null) { $request = \Requests::get($url . $path, $headers); } else { $request = \Requests::post($url . $path, $headers, $params); } return json_decode($request->body); }
public function call_rest_post($path, $data = array()) { $full_path = 'http' === substr($path, 0, 4) ? $path : $this->_api_path . $path; // Pb with SSL certificate. Disabled. $options = array('verify' => false, 'timeout' => 60); // Json format. $headers = array('Content-Type' => 'application/json'); $response = Requests::post($full_path, $headers, json_encode($data), $options); //var_dump( $response->body ); if (200 != $response->success) { return (object) array('status' => (object) array('state' => 'ERROR', 'message' => $response->body)); } return json_decode($response->body); }
function getTaobaoUserInfoAction() { $nick = urlencode($this->params('name')); $headers = ['Origin' => 'http://www.131458.com', 'Referer' => 'http://www.131458.com/', 'Content-Type' => 'application/json; charset=UTF-8']; $data = "{'nick':'" . $nick . "'}"; $response = \Requests::post('http://www.131458.com/handler/load.aspx/Load', $headers, $data); $d = json_decode($response->body, true); $session = $response->cookies['ASP.NET_SessionId']->value; if (is_array($d) && !empty($d['d'])) { $tokenResponse = \Requests::get('http://localhost:3000/token?d=' . $d['d'] . '&c=vvl'); $headers = ['Cookie' => 'ASP.NET_SessionId=' . $session]; $url = 'http://www.131458.com/handler/TaobaoInfo.ashx?tbNickInfoJson=' . $nick . '&token=' . $tokenResponse->body . '&_=' . time() * 1000; $taobaoInfoResponse = \Requests::get($url, $headers); $url = 'http://www.131458.com/handler/TaobaoInfo.ashx?nickCode=' . $nick . '&token=' . $tokenResponse->body . '&_=' . time() * 1000; $taobaoInfoResponse2 = \Requests::get($url, $headers); $document = \Api\Plugin\str_get_html($taobaoInfoResponse2->body); $info = []; $info['nickName'] = $document->find('.inq_02_L_001')[0]->find('a')[0]->text(); $info['registerTime'] = $document->find('.inq_02_L_002')[0]->find('span')[0]->text(); $info['realName'] = $document->find('.inq_02_L_003')[0]->find('span')[0]->text(); $info['address'] = $document->find('.inq_02_L_004')[1]->find('span')[0]->text(); $info['zhongping'] = $document->find('#zhongpingNumber')[0]->text(); $info['chapingNumber'] = $document->find('#chapingNumber')[0]->text(); $info['bili'] = $document->find('#zcbl')[0]->text(); $info['buyerLevel'] = $document->find('.inq_04_001')[0]->find('img')[0]->attr['src']; $dom = $document->find('.inq_04_001')[0]->find('a'); if (count($dom) > 0) { $info['buyerVipLevel'] = $document->find('.inq_04_001')[0]->find('a')[0]->find('img')[0]->attr['title']; } $info['buyerCredit'] = $document->find('.inq_04_001')[0]->find('b[name=p]')[0]->text(); $info['buyerWeek'] = $document->find('.inq_04_001')[1]->find('.qq')[0]->text(); $info['buyerMonth'] = $document->find('.inq_04_001')[2]->find('.qq')[0]->text(); $info['buyerHalfYear'] = $document->find('.inq_04_001')[3]->find('.qq')[0]->text(); $info['buyerHalfYearAgo'] = $document->find('.inq_04_001')[4]->find('.qq')[0]->text(); $info['buyerEveryWeek'] = $document->find('.inq_04_001')[5]->find('#bc')[0]->text(); $info['sellerLevel'] = $document->find('.inq_04_001')[6]->find('img')[0]->attr['src']; $info['sellerCredit'] = $document->find('.inq_04_001')[6]->find('b')[0]->text(); $info['sellerWeek'] = $document->find('.inq_04_001')[7]->find('b')[0]->text(); $info['sellerMonth'] = $document->find('.inq_04_001')[8]->find('b')[0]->text(); $info['sellerHalfYear'] = $document->find('.inq_04_001')[9]->find('b')[0]->text(); $info['sellerHalfYearAgo'] = $document->find('.inq_04_001')[10]->find('b')[0]->text(); $infojson = json_decode($taobaoInfoResponse->body, true); $info['SecurityLevel'] = str_get_html(urldecode($infojson[0]['SecurityLevel']))->find('img')[0]->attr['src']; echo json_encode($info); } else { echo ''; } exit; }