本文整理匯總了PHP中HttpRequest::setMethod方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpRequest::setMethod方法的具體用法?PHP HttpRequest::setMethod怎麽用?PHP HttpRequest::setMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HttpRequest
的用法示例。
在下文中一共展示了HttpRequest::setMethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sendPost
protected function sendPost($url, array $data = array())
{
$this->request->setUrl($this->getUrl($url));
$this->request->setMethod(\HttpRequest::METH_POST);
if (count($data)) {
$this->request->setPostFields($data);
}
$this->request->send();
}
示例2: request
protected function request($path, $args = array(), $files = array(), $envId = 0, $version = 'v1')
{
try {
$httpRequest = new HttpRequest();
$httpRequest->setMethod(HTTP_METH_POST);
$postData = json_encode($args);
$stringToSign = "/{$version}{$path}:" . $this->API_ACCESS_KEY . ":{$envId}:{$postData}:" . $this->API_SECRET_KEY;
$validToken = Scalr_Util_CryptoTool::hash($stringToSign);
$httpRequest->setHeaders(array("X_SCALR_AUTH_KEY" => $this->API_ACCESS_KEY, "X_SCALR_AUTH_TOKEN" => $validToken, "X_SCALR_ENV_ID" => $envId));
$httpRequest->setUrl("http://scalr-trunk.localhost/{$version}{$path}");
$httpRequest->setPostFields(array('rawPostData' => $postData));
foreach ($files as $name => $file) {
$httpRequest->addPostFile($name, $file);
}
$httpRequest->send();
if ($this->debug) {
print "<pre>";
var_dump($httpRequest->getRequestMessage());
var_dump($httpRequest->getResponseCode());
var_dump($httpRequest->getResponseData());
}
$data = $httpRequest->getResponseData();
return @json_decode($data['body']);
} catch (Exception $e) {
echo "<pre>";
if ($this->debug) {
var_dump($e);
} else {
var_dump($e->getMessage());
}
}
}
示例3: call
/**
* Makes api request
*
* @param string $qid The id of the query.
* @param array $options optional Query options for the request.
* @param string $path optional Uri path for the request (/user by default)
* @param string $method optional Http method (GET by default)
* @return object Returns object that is an response data.
* @throws CloudynException
*/
public function call($qid, array $options = array(), $path = '/user', $method = 'GET')
{
$options['qid'] = (string) $qid;
$options['out'] = self::OUT_JSON;
if (!isset($options['rqid'])) {
$options['rqid'] = $this->getRequestId();
}
if (!isset($options['apiversion'])) {
$options['apiversion'] = '0.4';
}
$this->request = $this->createNewRequest();
$this->request->setUrl($this->getUrl() . $path);
$this->request->setMethod(constant('HTTP_METH_' . strtoupper($method)));
$this->request->setOptions(array('redirect' => 10, 'useragent' => 'Scalr Client (http://scalr.com)'));
$this->request->addQueryData($options);
//This line is very necessary or HttpResponce will add stored cookies
$this->request->resetCookies();
$this->message = $this->tryCall($this->request);
$json = $this->message->getBody();
$json = preg_replace('#^[^\\{\\[]+|[^\\}\\]]+$#', '', trim($json));
$obj = json_decode($json);
if (isset($obj->status) && $obj->status != 'ok' && isset($obj->message)) {
throw new CloudynException('Cloudyn error. ' . $obj->message);
}
return $obj;
}
示例4: request
protected function request($method, $uri, $args)
{
$parsedUrl = parse_url($this->ec2Url);
$uri = "{$parsedUrl['path']}{$uri}";
$HttpRequest = new HttpRequest();
$HttpRequest->setOptions(array("useragent" => "Scalr (https://scalr.net)"));
$args['Version'] = $this->apiVersion;
$args['SignatureVersion'] = 2;
$args['SignatureMethod'] = "HmacSHA256";
$args['Timestamp'] = $this->getTimestamp();
$args['AWSAccessKeyId'] = $this->accessKeyId;
ksort($args);
foreach ($args as $k => $v) {
$CanonicalizedQueryString .= "&{$k}=" . rawurlencode($v);
}
$CanonicalizedQueryString = trim($CanonicalizedQueryString, "&");
$url = $parsedUrl['port'] ? "{$parsedUrl['host']}:{$parsedUrl['port']}" : "{$parsedUrl['host']}";
$args['Signature'] = $this->getSignature(array($method, $url, $uri, $CanonicalizedQueryString));
$HttpRequest->setUrl("{$parsedUrl['scheme']}://{$url}{$uri}");
$HttpRequest->setMethod(constant("HTTP_METH_{$method}"));
if ($args) {
if ($method == 'POST') {
$HttpRequest->setPostFields($args);
$HttpRequest->setHeaders(array('Content-Type' => 'application/x-www-form-urlencoded'));
} else {
$HttpRequest->addQueryData($args);
}
}
try {
$HttpRequest->send();
$data = $HttpRequest->getResponseData();
if ($HttpRequest->getResponseCode() == 200) {
$response = simplexml_load_string($data['body']);
if ($this->responseFormat == 'Object') {
$json = @json_encode($response);
$response = @json_decode($json);
}
if ($response->Errors) {
throw new Exception($response->Errors->Error->Message);
} else {
return $response;
}
} else {
$response = @simplexml_load_string($data['body']);
if ($response) {
throw new Exception($response->Error->Message);
}
throw new Exception(trim($data['body']));
}
$this->LastResponseHeaders = $data['headers'];
} catch (Exception $e) {
if ($e->innerException) {
$message = $e->innerException->getMessage();
} else {
$message = $e->getMessage();
}
throw new Exception($message);
}
}
示例5: OnStartForking
public function OnStartForking()
{
$db = \Scalr::getDb();
// Get pid of running daemon
$pid = @file_get_contents(CACHEPATH . "/" . __CLASS__ . ".Daemon.pid");
$this->Logger->info("Current daemon process PID: {$pid}");
// Check is daemon already running or not
if ($pid) {
$Shell = new Scalr_System_Shell();
// Set terminal width
putenv("COLUMNS=400");
// Execute command
$ps = $Shell->queryRaw("ps ax -o pid,ppid,command | grep ' 1' | grep {$pid} | grep -v 'ps x' | grep DBQueueEvent");
$this->Logger->info("Shell->queryRaw(): {$ps}");
if ($ps) {
// daemon already running
$this->Logger->info("Daemon running. All ok!");
return true;
}
}
$rows = $db->Execute("SELECT history_id FROM webhook_history WHERE status='0'");
while ($row = $rows->FetchRow()) {
$history = WebhookHistory::findPk(bin2hex($row['history_id']));
if (!$history) {
continue;
}
$endpoint = WebhookEndpoint::findPk($history->endpointId);
$request = new HttpRequest();
$request->setMethod(HTTP_METH_POST);
if ($endpoint->url == 'SCALR_MAIL_SERVICE') {
$request->setUrl('https://my.scalr.com/webhook_mail.php');
} else {
$request->setUrl($endpoint->url);
}
$request->setOptions(array('timeout' => 3, 'connecttimeout' => 3));
$dt = new DateTime('now', new DateTimeZone("UTC"));
$timestamp = $dt->format("D, d M Y H:i:s e");
$canonical_string = $history->payload . $timestamp;
$signature = hash_hmac('SHA1', $canonical_string, $endpoint->securityKey);
$request->addHeaders(array('Date' => $timestamp, 'X-Signature' => $signature, 'X-Scalr-Webhook-Id' => $history->historyId, 'Content-type' => 'application/json'));
$request->setBody($history->payload);
try {
$request->send();
$history->responseCode = $request->getResponseCode();
if ($request->getResponseCode() <= 205) {
$history->status = WebhookHistory::STATUS_COMPLETE;
} else {
$history->status = WebhookHistory::STATUS_FAILED;
}
} catch (Exception $e) {
$history->status = WebhookHistory::STATUS_FAILED;
}
$history->save();
}
}
示例6: request
protected function request($uri, $method, $data)
{
$httpRequest = new HttpRequest();
$httpRequest->setOptions(array("useragent" => "Scalr (https://scalr.net)"));
$httpRequest->setUrl("{$this->apiUrl}{$uri}");
$httpRequest->setMethod($method);
$httpRequest->resetCookies();
$httpRequest->addHeaders(array('Cookie' => $this->sessionCookie, 'Content-Type' => 'application/nimbula-v1+json'));
switch ($method) {
case HTTP_METH_POST:
$httpRequest->setRawPostData(json_encode($data));
$httpRequest->addHeaders(array('Content-Type' => 'application/nimbula-v1+json'));
break;
}
try {
$httpRequest->send();
$data = $httpRequest->getResponseData();
$result = @json_decode($data['body']);
if ($httpRequest->getResponseCode() > 204) {
$message = $result->message;
if ($message) {
if ($message instanceof stdClass) {
$r = (array) $message;
$msg = '';
foreach ($r as $k => $v) {
$msg .= "{$k}: {$v} ";
}
throw new Exception(trim($msg));
} else {
throw new Exception($message);
}
}
throw new Exception($data['body']);
}
$headers = $httpRequest->getResponseHeader('Set-Cookie');
if ($headers) {
if (!is_array($headers)) {
if (stristr($headers, "nimbula")) {
$this->sessionCookie = $headers;
}
} else {
}
}
$this->LastResponseHeaders = $data['headers'];
return $result;
} catch (Exception $e) {
if ($e->innerException) {
$message = $e->innerException->getMessage();
} else {
$message = $e->getMessage();
}
throw new Exception("Nimbula error: {$message}");
}
}
示例7: update
private function update($object)
{
$attr = $object->getAttributes();
$data = $this->encodeResponse($attr);
$url = $this->getMethodUrl(array('id' => $object->id));
$req = new HttpRequest();
$req->setUrl($url);
$req->setParam('data', $data);
$req->setMethod('POST');
$response = $req->perform();
$result = $this->decodeResponse($response);
return $this->validateResponse($result);
}
示例8: post
function post($url, $post_data)
{
$hr = new HttpRequest();
$hr->setURL($url);
$hr->setMethod('multipart');
foreach ($post_data as $name => $value) {
if ($name == 'file') {
$hr->addFile(array('name' => 'file', 'path' => $value['path'], 'filename' => $value['filename']));
} else {
$hr->addQuery(array('key' => $name, 'value' => $value));
}
}
$result = $hr->send();
return $result;
}
示例9: Request
private function Request($method, $uri, $args)
{
$HttpRequest = new HttpRequest();
$HttpRequest->setOptions(array("redirect" => 10, "useragent" => "LibWebta AWS Client (http://webta.net)"));
$timestamp = $this->GetTimestamp();
$URL = "queue.amazonaws.com";
if ($this->Region != 'us-east-1') {
$URL = "{$this->Region}.queue.amazonaws.com";
}
//EU URL: eu-west-1.queue.amazonaws.com
$args['Version'] = self::API_VERSION;
$args['SignatureVersion'] = 2;
$args['SignatureMethod'] = "HmacSHA1";
$args['Expires'] = $timestamp;
$args['AWSAccessKeyId'] = $this->AWSAccessKeyId;
ksort($args);
foreach ($args as $k => $v) {
$CanonicalizedQueryString .= "&{$k}=" . urlencode($v);
}
$CanonicalizedQueryString = trim($CanonicalizedQueryString, "&");
$args['Signature'] = $this->GetRESTSignature(array($method, $URL, $uri, $CanonicalizedQueryString));
$HttpRequest->setUrl("https://{$URL}{$uri}");
$HttpRequest->setMethod(constant("HTTP_METH_{$method}"));
if ($args) {
$HttpRequest->addQueryData($args);
}
try {
$HttpRequest->send();
//$info = $HttpRequest->getResponseInfo();
$data = $HttpRequest->getResponseData();
$this->LastResponseHeaders = $data['headers'];
$response = simplexml_load_string($data['body']);
if ($response->Error) {
throw new Exception($response->Error->Message);
} else {
return $response;
}
} catch (Exception $e) {
if ($e->innerException) {
$message = $e->innerException->getMessage();
} else {
$message = $e->getMessage();
}
throw new Exception($message);
}
}
示例10: testGeneral
public function testGeneral()
{
$httpRequest = new HttpRequest('http://tuoitre.com.vn/conduongcuqua?q=example_query&page=2&t[]=4');
$this->assertEquals(['example_query'], $httpRequest->getList('q'));
$this->assertEquals('example_query', $httpRequest->getParam('q'));
$this->assertEquals('example_query', $httpRequest->getString('q'));
$defaultValue = 'testvalue';
$this->assertEmpty($httpRequest->getGET());
$this->assertEmpty($httpRequest->getPOST());
$this->assertNotEmpty($httpRequest->getQuery());
$this->assertEmpty($httpRequest->getPOST());
$this->assertEquals('2', $httpRequest->getParam('page'));
$this->assertEquals(2, $httpRequest->getInt('page'));
$this->assertEquals(['4'], $httpRequest->getArray('t'));
$this->assertEmpty([], $httpRequest->getArray('no_array'));
$this->assertEquals([1], $httpRequest->getArray('no_array', [1]));
$this->assertEquals($defaultValue, $httpRequest->getParam('no_query', $defaultValue));
$this->assertEquals($defaultValue, $httpRequest->getString('no_query', $defaultValue));
$this->assertEquals($defaultValue, $httpRequest->getParam('no_query', $defaultValue));
$this->assertTrue($httpRequest->isMethod('get'));
$httpRequest->getResponse();
$this->assertEmpty($httpRequest->getFragment());
$httpRequest->setMethod('post');
$this->assertTrue($httpRequest->isPost());
$exception = new \RuntimeException('issue');
$httpRequest->setException($exception);
$this->assertEquals($exception, $httpRequest->getException());
$httpRequest->example_params = 12;
$this->assertEquals($httpRequest->example_params, 12);
$httpRequest->setPath('/');
$this->assertEquals($httpRequest->getPath(), '/');
$httpRequest->setDispatched(false);
$this->assertFalse($httpRequest->isDispatched());
$httpRequest->setControllerName('\\Platform\\Core\\Controller\\HomeController');
$httpRequest->setActionName('index');
$this->assertEquals($httpRequest->getControllerName(), '\\Platform\\Core\\Controller\\HomeController');
$this->assertEquals($httpRequest->getActionName(), 'index');
$httpRequest->dispatch();
$httpRequest->setParams(['more' => '2']);
$this->assertNotEmpty($httpRequest->getParams());
$this->assertEquals('2', $httpRequest->getParam('more'));
$httpRequest->getFullControllerName();
}
示例11: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$start_time = microtime(true);
$HttpRequest = new HttpRequest();
$HttpRequest->setOptions(array("redirect" => 10, "useragent" => "Scalr (http://scalr.net) HTTPResponseTime Scaling Sensor", "connecttimeout" => 10));
$HttpRequest->setUrl($farmRoleMetric->getSetting(self::SETTING_URL));
$HttpRequest->setMethod(constant("HTTP_METH_GET"));
try {
$HttpRequest->send();
} catch (Exception $e) {
if ($e->innerException) {
$message = $e->innerException->getMessage();
} else {
$message = $e->getMessage();
}
throw new Exception("HTTPResponseTime Scaling Sensor cannot get value: {$message}");
}
$retval = round(microtime(true) - $start_time, 2);
return array($retval);
}
示例12: Request
private function Request($method, $uri, $request_body, $query_args, $headers = array())
{
$HttpRequest = new HttpRequest();
$HttpRequest->setOptions(array("redirect" => 10, "useragent" => "LibWebta AWS Client (http://webta.net)"));
$timestamp = $this->GetTimestamp();
$signature = $this->GetRESTSignature($timestamp);
$HttpRequest->setUrl("https://cloudfront.amazonaws.com/" . self::API_VERSION . $uri);
$HttpRequest->setMethod($method);
if ($query_args) {
$HttpRequest->addQueryData($query_args);
}
if ($request_body) {
if ($method == constant("HTTP_METH_POST")) {
$HttpRequest->setRawPostData(trim($request_body));
} else {
$HttpRequest->setPutData(trim($request_body));
}
$headers["Content-type"] = "text/xml";
}
$headers["Date"] = $timestamp;
$headers["Authorization"] = "AWS {$this->AWSAccessKeyId}:{$signature}";
$HttpRequest->addHeaders($headers);
try {
$HttpRequest->send();
//$info = $HttpRequest->getResponseInfo();
$data = $HttpRequest->getResponseData();
$this->LastResponseHeaders = $data['headers'];
return $data['body'];
} catch (Exception $e) {
if ($e->innerException) {
$message = $e->innerException->getMessage();
} else {
$message = $e->getMessage();
}
throw new Exception($message);
}
}
示例13: request
public function request($method, stdClass $params = null, $namespace = null)
{
if (!$namespace) {
$namespace = $this->namespace;
}
$requestObj = new stdClass();
$requestObj->id = microtime(true);
$requestObj->method = $method;
$requestObj->params = new stdClass();
$this->walkSerialize($params, $requestObj->params, 'underScope');
$jsonRequest = $this->cryptoTool->encrypt(json_encode($requestObj), $this->dbServer->GetKey(true));
$dt = new DateTime('now', new DateTimeZone("UTC"));
$timestamp = $dt->format("D d M Y H:i:s e");
$canonical_string = $jsonRequest . $timestamp;
$signature = base64_encode(hash_hmac('SHA1', $canonical_string, $this->dbServer->GetKey(true), 1));
$request = new HttpRequest();
$request->setMethod(HTTP_METH_POST);
// If no VPC router communicating via local inteface (Scalr should be setup within the esame network)
$requestHost = $this->dbServer->getSzrHost() . ":{$this->port}";
if ($this->isVPC) {
$routerFarmRoleId = $this->dbServer->GetFarmRoleObject()->GetSetting(Scalr_Role_Behavior_Router::ROLE_VPC_SCALR_ROUTER_ID);
if ($routerFarmRoleId) {
$routerRole = DBFarmRole::LoadByID($routerFarmRoleId);
} else {
$routerRole = $this->dbServer->GetFarmObject()->GetFarmRoleByBehavior(ROLE_BEHAVIORS::VPC_ROUTER);
}
if ($routerRole) {
// No public IP need to use proxy
if (!$this->dbServer->remoteIp) {
$requestHost = $routerRole->GetSetting(Scalr_Role_Behavior_Router::ROLE_VPC_IP) . ":80";
$request->addHeaders(array("X-Receiver-Host" => $this->dbServer->localIp, "X-Receiver-Port" => $this->port));
// There is public IP, can use it
} else {
$requestHost = "{$this->dbServer->remoteIp}:{$this->port}";
}
}
}
$request->setUrl("http://{$requestHost}/{$namespace}");
$request->setOptions(array('timeout' => $this->timeout, 'connecttimeout' => 10));
$request->addHeaders(array("Date" => $timestamp, "X-Signature" => $signature, "X-Server-Id" => $this->dbServer->serverId));
$request->setBody($jsonRequest);
try {
// Send request
$request->send();
$this->debug['responseCode'] = $request->getResponseCode();
$this->debug['fullResponse'] = $request->getRawResponseMessage();
if ($request->getResponseCode() == 200) {
$response = $request->getResponseData();
$body = $this->cryptoTool->decrypt($response['body'], $this->dbServer->GetKey(true));
$jResponse = @json_decode($body);
if ($jResponse->error) {
throw new Exception("{$jResponse->error->message} ({$jResponse->error->code}): {$jResponse->error->data}");
}
return $jResponse;
} else {
$response = $request->getResponseData();
throw new Exception(sprintf("Unable to perform request to scalarizr: %s (%s)", $response['body'], $request->getResponseCode()));
}
} catch (HttpException $e) {
if (isset($e->innerException)) {
$msg = $e->innerException->getMessage();
} else {
$msg = $e->getMessage();
}
if (stristr($msg, "Namespace not found")) {
$msg = "Feature not supported by installed version of scalarizr. Please update it to the latest version and try again.";
}
throw new Exception(sprintf("Unable to perform request to scalarizr: %s", $msg));
}
}
示例14: removeUser
public function removeUser($id)
{
$url = $this->makeServiceURL(self::API_USER_BASE_URL, '/user/' . $id);
$req = new HttpRequest();
$req->setUrl($url);
$req->setMethod('DELETE');
return $req->perform();
}
示例15: HttpRequest
<?php
$request = new HttpRequest();
$request->setUrl('https://mockbin.com/har');
$request->setMethod(HTTP_METH_GET);
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}