本文整理汇总了PHP中Requests::post方法的典型用法代码示例。如果您正苦于以下问题:PHP Requests::post方法的具体用法?PHP Requests::post怎么用?PHP Requests::post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Requests
的用法示例。
在下文中一共展示了Requests::post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: httpPostRequest
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);
}
示例2: post
/**
* 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;
}
示例3: checkDomain
/**
* 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']);
}
示例4: getStations
/**
* 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');
}
}
示例5: openOrder
/**
* 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;
}
示例6: httpPostRequest
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);
}
示例7: 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;
}
}
示例8: 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;
}
示例9: basePost
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']);
}
示例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...
}
示例11: index
/**
* 버전정보 페이지입니다
*/
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));
}
示例12: doPost
/**
* @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);
}
示例13: request
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;
}
示例14: kirim_pasien
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);
}
示例15: testPOSTWithArray
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']);
}