本文整理匯總了PHP中HttpRequest::setUrl方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpRequest::setUrl方法的具體用法?PHP HttpRequest::setUrl怎麽用?PHP HttpRequest::setUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HttpRequest
的用法示例。
在下文中一共展示了HttpRequest::setUrl方法的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: 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();
}
}
示例3: 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());
}
}
}
示例4: keyword_search
public function keyword_search($keyword)
{
// 從 Google 取得搜尋結果(HTML原始碼)
$keyword = urlencode($keyword);
$url = "https://www.google.com.tw/webhp?hl=zh-TW#hl=zh-TW&q={$keyword}&num=10";
$httpReq = new HttpRequest();
$httpReq->setUrl($url);
$content = $httpReq->submit();
unset($httpReq);
$results = array();
// 分析原始碼並取得每個項目
if (preg_match_all('/<!--m-->(.*?)<!--n-->/s', $content, $items)) {
$idx = 0;
foreach ($items[1] as $key => $item) {
$resultItem = new ResultItem();
$resultItem->sequence = $idx + 1;
$resultItem->title = preg_match('/<a .*?>(.*?)<\\/a>/s', $item, $res) ? trim($res[1]) : "";
$resultItem->link = urldecode(preg_match('/<h3 class="r"><a href="(.*?)".*?>.*?<\\/a>/s', $item, $res) ? trim($res[1]) : "");
$resultItem->description = preg_match('/<span class="st">(<span class="f">(.*?)<\\/span>)?(.*?)<\\/span>/s', $item, $res) ? trim($res[3]) : "";
$resultItem->save_date = str_replace(" - ", "", $res[2]);
if (trim($resultItem->link) == "") {
continue;
}
$idx++;
$results[] = $resultItem;
}
}
return $results;
}
示例5: 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;
}
示例6: 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);
}
}
示例7: 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}");
}
}
示例8: 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);
}
示例9: findWithOptions
public function findWithOptions($options)
{
$req = new HttpRequest();
$url = $this->getMethodUrl($options);
$req->setUrl($url);
$req->setParams($options);
$response = $req->perform();
$result = $this->decodeResponse($response);
if (isset($result['error'])) {
throw new RemoteException($result['error']);
}
return $this->createResultDataSet($result);
}
示例10: 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);
}
}
示例11: format
/**
* @inheritdoc
*/
public function format(HttpRequest $request)
{
$data = (array) $request->getData();
$content = http_build_query($data, '', '&', $this->encodingType);
if (strcasecmp('get', $request->getMethod()) === 0) {
if (!empty($content)) {
$url = $request->getUrl();
$url .= strpos($url, '?') === false ? '?' : '&';
$url .= $content;
$request->setUrl($url);
}
return $request;
}
$request->addHeader('Content-Type', 'application/x-www-form-urlencoded');
$request->setContent($content);
return $request;
}
示例12: 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);
}
示例13: 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);
}
}
示例14: 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));
}
}
示例15: 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();
}