本文整理汇总了PHP中Unirest\Request::post方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::post方法的具体用法?PHP Request::post怎么用?PHP Request::post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Unirest\Request
的用法示例。
在下文中一共展示了Request::post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendContent
public function sendContent($from, $to, $subject, $type, $content)
{
if (is_string($to)) {
$to = [$to];
}
$recipients = Mailjet::parse_recipient_type($to);
// Build the HTTP POST body text
if ($type == 'html') {
$body = http_build_query(array('from' => $from, 'to' => implode(', ', $recipients['to']), 'cc' => implode(', ', $recipients['cc']), 'bcc' => implode(', ', $recipients['bcc']), 'subject' => $subject, 'html' => $content));
} else {
if ($type == 'text') {
$body = http_build_query(array('from' => $from, 'to' => implode(', ', $recipients['to']), 'cc' => implode(', ', $recipients['cc']), 'bcc' => implode(', ', $recipients['bcc']), 'subject' => $subject, 'text' => $content));
} else {
throw new Exception('Wrong email type');
}
}
utils::log($body);
$options = array('scheme' => 'http', 'host' => 'api.mailjet.com', 'path' => '/v3/send/');
$endpoint = Mailjet::unparse_url($options);
$headers = array('Authorization' => 'Basic ' . $this->_authentificate, 'Content-Type' => 'application/x-www-form-urlencoded', 'Content-Length' => strlen($body));
// API request
Unirest\Request::verifyPeer(false);
$response = Unirest\Request::post($endpoint, $headers, $body);
utils::log('STATUS: ' . $response->code);
utils::log('HEADERS: ' . json_encode($response->headers));
utils::log('BODY: ' . $response->raw_body);
return $response->code == 200;
}
示例2: performTransaction
/**
* [performTransaction description].
*
* @return [type] [description]
*/
protected function performTransaction()
{
$this->prepareRequest();
$unirestResponse = Unirest::post($this->endpoint, array(), $this->requestBody);
$this->responseXMLString = $unirestResponse->body;
$this->responseXML = simplexml_load_string($this->responseXMLString);
}
示例3: post
public static function post($body = null, $headers = null)
{
if (!$headers) {
$headers = Rapid::getAuthHeader();
}
$response = Request::post(Rapid::getUrl(self::$route), $headers, http_build_query($body));
return Response::make($response);
}
示例4: postInfo
public function postInfo($url, $inputs = null, $param = null)
{
$url = setApiUrl($url, $param);
//Log::info($url);
$response = Unirest\Request::post($url, $this->_headers, json_encode($inputs));
//Log::info(json_encode($response));
return dealResponse($response);
}
示例5: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
HTTPRequest::verifyPeer(env('UNIREST_VERIFYPEER'));
//Get 10 quotes, from a Mashape API
for ($i = 0; $i < 10; $i++) {
$response = HTTPRequest::post("https://andruxnet-random-famous-quotes.p.mashape.com/cat=famous", array("X-Mashape-Key" => env('MASHAPE_KEY'), "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json"));
Quote::create(["content" => $response->body->quote, "author" => $response->body->author, "source" => "https://andruxnet-random-famous-quotes.p.mashape.com/cat=famous"]);
}
}
示例6: createAllowedAddress
/**
* Create email to sms allowed address
* @param string $emailAddress Required parameter: Your email address.
* @param string $from Required parameter: Your phone number in E.164 format.
* @return string response from the API call*/
public function createAllowedAddress($emailAddress, $from)
{
//check that all required arguments are provided
if (!isset($emailAddress, $from)) {
throw new \InvalidArgumentException("One or more required arguments were NULL.");
}
//the base uri for api requests
$_queryBuilder = Configuration::$BASEURI;
//prepare query string for API call
$_queryBuilder = $_queryBuilder . '/sms/email-sms';
//process optional query parameters
APIHelper::appendUrlWithQueryParameters($_queryBuilder, array('email_address' => $emailAddress, 'from' => $from));
//validate and preprocess url
$_queryUrl = APIHelper::cleanUrl($_queryBuilder);
//prepare headers
$_headers = array('user-agent' => 'ClickSendSDK');
//set HTTP basic auth parameters
Request::auth(Configuration::$username, Configuration::$key);
//and invoke the API call request to fetch the response
$response = Request::post($_queryUrl, $_headers);
//Error handling using HTTP status codes
if ($response->code == 400) {
throw new APIException('BAD_REQUEST', 400, $response->body);
} else {
if ($response->code == 401) {
throw new APIException('UNAUTHORIZED', 401, $response->body);
} else {
if ($response->code == 403) {
throw new APIException('FORBIDDEN', 403, $response->body);
} else {
if ($response->code == 404) {
throw new APIException('NOT_FOUND', 404, $response->body);
} else {
if ($response->code == 405) {
throw new APIException('METHOD_NOT_FOUND', 405, $response->body);
} else {
if ($response->code == 429) {
throw new APIException('TOO_MANY_REQUESTS', 429, $response->body);
} else {
if ($response->code == 500) {
throw new APIException('INTERNAL_SERVER_ERROR', 500, $response->body);
} else {
if ($response->code < 200 || $response->code > 206) {
//[200,206] = HTTP OK
throw new APIException("HTTP Response Not OK", $response->code, $response->body);
}
}
}
}
}
}
}
}
return $response->body;
}
示例7: UnirestapiRegister
/**
* @param string $doUrl
* @param string $method
* @param string $content
* @return boolean or object
*/
protected function UnirestapiRegister($content)
{
$apiUrl = $this->_apiUrl;
$url = $apiUrl . "/register";
$headers = array("Content-Type" => "application/json", "Accept" => "application/json");
$response = Unirest\Request::post($url, $headers, json_encode($content));
if ($response->code == '201') {
$res['code'] = 200;
$res['body'] = $response->body;
return $res;
} elseif ($response->code == '403') {
$res['code'] = 403;
$res['body'] = "This email has exist.";
return $res;
}
return false;
}
示例8: comfirmPurchase
public function comfirmPurchase($inputs)
{
$url = setApiUrl("numbers.buyNumbers");
$response = Unirest\Request::post($url, $this->_headers, json_encode($inputs));
// return json_encode($response);
$response = dealResponse($response);
if ($response['flag'] == 'success') {
$data = $response['data'];
if ($data->total != $data->succeed) {
$response['flag'] = 'error';
$response['msg'] = $data->failed_list;
unset($response['pagging']);
return json_encode($response);
} else {
$response['msg'] = 'Buy numbers successfully';
}
}
return json_encode($response);
}
示例9: createConfiguration
/**
* Apply a given configuration to one or more numbers
* @param DidConfigurationModel $body Required parameter: TODO: type description here
* @return mixed response from the API call*/
public function createConfiguration($body)
{
//the base uri for api requests
$queryBuilder = Configuration::BASEURI;
$queryBuilder = Config::get('voxbone.base_uri');
//prepare query string for API call
$queryBuilder = $queryBuilder . '/configuration/configuration';
//validate and preprocess url
$queryUrl = APIHelper::cleanUrl($queryBuilder);
//prepare headers
$headers = array('User-Agent' => 'APIMATIC 2.0', 'Accept' => 'application/json', 'Content-type' => 'application/json; charset=utf-8');
//prepare API request
$response = Request::post($queryUrl, $headers, json_encode($body));
//and invoke the API call request to fetch the response
//$response = Unirest::getResponse($request);
//Error handling using HTTP status codes
if ($response->code < 200 || $response->code > 206) {
//[200,206] = HTTP OK
return $response;
}
return $response->body;
}
示例10: request
public function request($path, $params, $headers = [], $isSecure = false)
{
$params['appid'] = $this->options['appid'];
$params['mch_id'] = $this->options['mch_id'];
$params['nonce_str'] = $this->getNonce();
$params['sign'] = $this->sign($params);
$xml = $this->xmlEncode($params);
if ($isSecure) {
Request::curlOpt(CURLOPT_SSLCERTTYPE, 'PEM');
Request::curlOpt(CURLOPT_SSLCERT, $this->options['cert']);
Request::curlOpt(CURLOPT_SSLKEYTYPE, 'PEM');
Request::curlOpt(CURLOPT_SSLKEY, $this->options['private']);
}
/**
* @var $res \Unirest\Response
*/
$res = Request::post(sprintf('%s%s', $this->options['host'], $path), $headers, $xml);
if ($isSecure) {
Request::clearCurlOpts();
}
if ($res->code !== 200) {
throw new \Exception('Invalid response status code', $res->code);
}
$body = $this->xmlDecode($res->body);
if (!is_array($body)) {
throw new \Exception(sprintf('Invalid response body: %s', $res->body));
}
if ($body['return_code'] !== static::SUCCESS) {
throw new \Exception(sprintf('Invalid return_code: %s', $res->body));
}
if ($body['appid'] !== $this->options['appid'] || $body['mch_id'] !== $this->options['mch_id']) {
throw new \Exception(sprintf('Invalid appid or mch_id: %s', $res->body));
}
$sign = $body['sign'];
if ($sign !== $this->sign($body)) {
throw new \Exception(sprintf('Invalid sign: %s', $res->body));
}
return $body;
}
示例11: call
/**
* The underlying call to the Kong Server
*
* @throws \Ignittion\Kong\KongException when something goes wrong with the Http request
*
* @param string $verb
* @param string $uri
* @param array $options
* @param array $body
* @return \stdClass
*/
public function call($verb, $uri, array $params = [], array $body = [], array $headers = [])
{
$verb = strtoupper($verb);
$api = "{$this->url}:{$this->port}/{$uri}";
$headers = array_merge($headers, ['Content-Type: application/json']);
try {
switch ($verb) {
case 'GET':
$request = RestClient::get($api, $headers, $params);
break;
case 'POST':
$request = RestClient::post($api, $headers, $body);
break;
case 'PUT':
$request = RestClient::put($api, $headers, $body);
break;
case 'PATCH':
$request = RestClient::patch($api, $headers, $body);
break;
case 'DELETE':
$request = RestClient::delete($api, $headers);
break;
default:
throw new Exception('Unknown HTTP Request method.');
}
} catch (Exception $e) {
throw new KongException($e->getMessage());
}
// save this request
$this->body = $request->body;
$this->headers = $request->headers;
$this->httpCode = $request->code;
$this->rawBody = $request->raw_body;
// return a more simplified response
$object = new stdClass();
$object->code = $this->httpCode;
$object->data = $this->body;
return $object;
}
示例12: createCdrsFileRequest
/**
* Request the generation of a call report for a full month
* @param string $year Required parameter: The year in YYYY format
* @param string $month Required parameter: The month in MM format
* @return mixed response from the API call*/
public function createCdrsFileRequest($year, $month)
{
//the base uri for api requests
$queryBuilder = Configuration::BASEURI;
$queryBuilder = Config::get('voxbone.base_uri');
//prepare query string for API call
$queryBuilder = $queryBuilder . '/cdrs/cdrsfile/request/{year}/{month}';
//process optional query parameters
APIHelper::appendUrlWithTemplateParameters($queryBuilder, array('year' => $year, 'month' => $month));
//validate and preprocess url
$queryUrl = APIHelper::cleanUrl($queryBuilder);
//prepare headers
$headers = array('User-Agent' => 'APIMATIC 2.0', 'Accept' => 'application/json', 'Content-type' => 'application/json; charset=utf-8');
//prepare API request
$response = Request::post($queryUrl, $headers);
//and invoke the API call request to fetch the response
//$response = Unirest::getResponse($request);
//Error handling using HTTP status codes
if ($response->code < 200 || $response->code > 206) {
//[200,206] = HTTP OK
return $response;
}
return $response->body;
}
示例13: array
$response->body($core->twig->render('node/403.html'))->send();
return;
}
if (!$core->auth->XSRF($request->param('xsrf'))) {
$service->flash('<div class="alert alert-warning"> The XSRF token recieved was not valid. Please make sure cookies are enabled and try your request again.</div>');
$response->redirect('/node/settings?tab=ftp_sett')->send();
}
if (!$core->auth->validatePasswordRequirements($request->param('sftp_pass'))) {
$service->flash('<div class="alert alert-danger">The password you provided does not meet the requirements. Please use at least 8 characters, include at least one number, and use mixed case.</div>');
$response->redirect('/node/settings?tab=sftp_sett')->send();
} else {
/*
* Update Server FTP Information
*/
try {
$unirest = Unirest\Request::post('https://' . $core->server->nodeData('fqdn') . ':' . $core->server->nodeData('daemon_listen') . '/server/reset-password', array("X-Access-Token" => $core->server->nodeData('daemon_secret'), "X-Access-Server" => $core->server->getData('hash')), array("password" => $request->param('sftp_pass')));
if ($unirest->code === 204) {
$service->flash('<div class="alert alert-success">Your SFTP password has been updated.</div>');
$response->redirect('/node/settings?tab=sftp_sett')->send();
} else {
throw new \Exception("Scales did not return a success code while attempting to reset an account password. (code: " . $unirest->code . ")");
}
} catch (\Exception $e) {
Tracy\Debugger::log($e);
$service->flash('<div class="alert alert-danger">Unable to access the Scales daemon to reset your password. Please try again in a moment.</div>');
$response->redirect('/node/settings?tab=sftp_sett')->send();
}
}
});
$klein->respond('POST', '/node/settings/password', function ($request, $response) use($core) {
$response->body($core->auth->keygen(rand(6, 10)) . "-" . $core->auth->keygen(rand(6, 14)))->send();
示例14: foreach
if (empty($command)) {
$service->flash('<div class="alert alert-warning">You entered an invalid command.</div>');
$response->redirect('/scs')->send();
return;
}
foreach ($servers as $server) {
$serverToSendCommand = null;
foreach ($serversArray as $srv) {
if ($srv['hash'] === $server) {
$serverToSendCommand = $srv;
}
}
if ($serverToSendCommand != null) {
$node = ORM::forTable('nodes')->select('nodes.*')->where('id', $serverToSendCommand['node'])->findArray()[0];
try {
Unirest\Request::post("https://" . $node['fqdn'] . ":" . $node['daemon_listen'] . "/server/console", array("X-Access-Token" => $node['daemon_secret'], "X-Access-Server" => $server), array("command" => $command));
} catch (\Exception $e) {
\Tracy\Debugger::log($e);
$service->flash('<div class="alert alert-danger">A problem happened while sending the command to the target servers.</div>');
$response->redirect('/scs')->send();
return;
}
} else {
$service->flash('<div class="alert alert-warning">One of the servers you selected was invalid.</div>');
}
}
$service->flash('<div class="alert alert-success">Your command has been sent successfully.</div>');
$response->redirect('/scs')->send();
});
$klein->respond('GET', '/totp', function ($request, $response, $service) use($core) {
$response->body($core->twig->render('panel/totp.html', array('totp' => $core->user->getData('use_totp'), 'xsrf' => $core->auth->XSRF(), 'flash' => $service->flashes())))->send();
示例15: time
$storage_variables .= $name . "|" . $value . "\n";
}
$server = ORM::forTable('servers')->create();
$server->set(array('hash' => $server_hash, 'daemon_secret' => $daemon_secret, 'node' => $request->param('node'), 'name' => $request->param('server_name'), 'plugin' => $plugin->id, 'daemon_startup' => $request->param('daemon_startup'), 'daemon_variables' => $storage_variables, 'owner_id' => $user->id, 'max_ram' => $request->param('alloc_mem'), 'disk_space' => 0, 'cpu_limit' => $request->param('cpu_limit'), 'block_io' => $request->param('block_io'), 'date_added' => time(), 'server_ip' => $request->param('server_ip'), 'server_port' => $request->param('server_port'), 'sftp_user' => $sftp_username, 'installed' => 0));
$server->save();
$ips[$request->param('server_ip')]['ports_free']--;
$ports[$request->param('server_ip')][$request->param('server_port')]--;
$node->ips = json_encode($ips);
$node->ports = json_encode($ports);
$node->save();
/*
* Build Call
*/
$data = array("name" => $server_hash, "user" => $sftp_username, "build" => array("disk" => array("hard" => $request->param('alloc_disk') < 32 ? 32 : (int) $request->param('alloc_disk'), "soft" => $request->param('alloc_disk') > 2048 ? (int) $request->param('alloc_disk') - 1024 : 32), "cpu" => (int) $request->param('cpu_limit'), "memory" => (int) $request->param('alloc_mem'), "io" => (int) $request->param('block_io')), "startup" => array("command" => $request->param('daemon_startup'), "variables" => $startup_variables), "keys" => array($daemon_secret => array("s:ftp", "s:get", "s:power", "s:files", "s:files:get", "s:files:delete", "s:files:put", "s:files:zip", "s:query", "s:console", "s:console:send")), "gameport" => (int) $request->param('server_port'), "gamehost" => $request->param('server_ip'), "plugin" => $request->param('plugin'));
try {
$unirest = Request::post('https://' . $node->fqdn . ':' . $node->daemon_listen . '/server', array('X-Access-Token' => $node->daemon_secret, 'X-Access-Server' => "hodor"), array('settings' => json_encode($data), 'password' => $core->auth->keygen(16), 'build_params' => $request->param('plugin_variable_build_params') ? $request->param('plugin_variable_build_params') : false));
if ($unirest->code !== 204) {
throw new Exception("An error occured trying to add a server. (" . $unirest->raw_body . ") [HTTP 1.1/" . $unirest->code . "]");
}
ORM::get_db()->commit();
} catch (Exception $e) {
Debugger::log($e);
ORM::get_db()->rollBack();
$service->flash('<div class="alert alert-danger">An error occured while trying to connect to the remote node. Please check that Scales is running and try again.</div>');
$response->redirect('/admin/server/new')->send();
return;
}
$service->flash('<div class="alert alert-success">Server created successfully.</div>');
$response->redirect('/admin/server/view/' . $server->id() . '?tab=installer')->send();
return;
});