本文整理汇总了PHP中HttpRequest::getResponseCode方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpRequest::getResponseCode方法的具体用法?PHP HttpRequest::getResponseCode怎么用?PHP HttpRequest::getResponseCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest::getResponseCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Performs the test.
*
* @return \Jyxo\Beholder\Result
*/
public function run()
{
// The http extension is required
if (!extension_loaded('http')) {
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Extension http missing');
}
$http = new \HttpRequest($this->url, \HttpRequest::METH_GET, array('connecttimeout' => 5, 'timeout' => 10, 'useragent' => 'JyxoBeholder'));
try {
$http->send();
if (200 !== $http->getResponseCode()) {
throw new \Exception(sprintf('Http error: %s', $http->getResponseCode()));
}
if (isset($this->tests['body'])) {
$body = $http->getResponseBody();
if (!preg_match($this->tests['body'], $body)) {
$body = trim(strip_tags($body));
throw new \Exception(sprintf('Invalid body: %s', \Jyxo\String::cut($body, 16)));
}
}
// OK
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS);
} catch (\HttpException $e) {
$inner = $e;
while (null !== $inner->innerException) {
$inner = $inner->innerException;
}
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, $inner->getMessage());
} catch (\Exception $e) {
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, $e->getMessage());
}
}
示例2: query_url_request
/**
* Copyright (C) 2008-2010 Ulteo SAS
* http://www.ulteo.com
* Author Julien LANGLOIS <julien@ulteo.com>
* Author Laurent CLOUET <laurent@ulteo.com>
* Author Jeremy DESVAGES <jeremy@ulteo.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
function query_url_request($url_, $log_returned_data_ = true, $data_in_file_ = false)
{
Logger::debug('main', "query_url_request({$url_},{$log_returned_data_}, {$data_in_file_})");
$hr = new HttpRequest($url_, 'GET');
if ($data_in_file_ === true) {
$data_file = tempnam(NULL, 'curl_');
$fp = fopen($data_file, 'w');
$hr->setToFile($fp);
}
$data = $hr->send();
if ($data_in_file_ === true) {
$data = $data_file;
fclose($fp);
}
if ($data === false) {
Logger::error('main', "query_url_request({$url_}) error code: " . $hr->getResponseErrno() . " text: '" . $hr->getResponseError() . "'");
} else {
if (str_startswith($hr->getResponseContentType(), 'text/') && $log_returned_data_ === true) {
Logger::debug('main', "query_url_request({$url_}) returntext: '{$data}'");
}
}
if ($hr->getResponseCode() != 200) {
Logger::debug('main', "query_url_request({$url_}) returncode: '" . $hr->getResponseCode() . "'");
}
return array('data' => $data, 'code' => $hr->getResponseCode(), 'content_type' => $hr->getResponseContentType());
}
示例3: 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();
}
}
示例4: sendRequest
/**
* Send the request
*
* This function sends the actual request to the
* remote/local webserver using pecl http
*
* @link http://us2.php.net/manual/en/http.request.options.php
* @todo catch exceptions from HttpRequest and rethrow
* @todo handle Puts
*/
public function sendRequest()
{
$options = array('connecttimeout' => $this->requestTimeout);
// if we have any listeners register an onprogress callback
if (count($this->_listeners) > 0) {
$options['onprogress'] = array($this, '_onprogress');
}
$tmp = 'HTTP_METH_' . strtoupper($this->verb);
if (defined($tmp)) {
$method = constant($tmp);
} else {
$method = HTTP_METH_GET;
}
$this->request = $request = new \HttpRequest($this->uri->url, $method, $options);
$request->setHeaders($this->headers);
if ($this->body) {
$request->setRawPostData($this->body);
}
$request->send();
$response = $request->getResponseMessage();
$body = $response->getBody();
$details = $this->uri->toArray();
$details['code'] = $request->getResponseCode();
$details['httpVersion'] = $response->getHttpVersion();
$headers = new Request\Headers($response->getHeaders());
$cookies = $request->getResponseCookies();
return new Request\Response($details, $body, $headers, $cookies);
}
示例5: testDeleteAsset
public function testDeleteAsset()
{
$assetID = file_get_contents('test.assetid');
$r = new HttpRequest($this->server_url . $assetID, HttpRequest::METH_DELETE);
$r->send();
$this->assertEquals(200, $r->getResponseCode());
}
示例6: 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());
}
}
}
示例7: 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);
}
}
示例8: query_draw_history
/**
* Query past cashpot draws by date.
* @param day a two digit representation of the day eg. 09
* @param month a three letter representation of the month eg. Jan
* @param year a two digit representation of the year eg. 99
* @return the raw html from the page returned by querying a past cashpot draw.
*/
function query_draw_history($day, $month, $year)
{
$url = "http://www.nlcb.co.tt/search/cpq/cashQuery.php";
$fields = array('day' => $day, 'month' => $month, 'year' => $year);
$request = new HttpRequest($url, HttpRequest::METH_POST);
$request->addPostFields($fields);
try {
$request->send();
if ($request->getResponseCode() == 200) {
$response = $request->getResponseBody();
} else {
throw new Exception("Request for {$url} was unsuccessful. A " . $request->getResponseCode() . " response code was returned.");
}
} catch (HttpException $e) {
echo $e->getMessage();
throw $e;
}
return $response;
}
示例9: test
public function test()
{
$route = 'http://localhost/wordpress/augsburg/de/wp-json/extensions/v0/
modified_content/posts_and_pages';
$r = new HttpRequest($route, HttpRequest::METH_GET);
$r->addQueryData(array('since' => '2000-01-01T00:00:00Z'));
$r->send();
$this->assertEquals(200, $r->getResponseCode());
$body = $r->getResponseBody();
}
示例10: 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}");
}
}
示例11: http_get_file
function http_get_file($url)
{
$r = new HttpRequest($url, HttpRequest::METH_GET);
$r->setOptions(array('redirect' => 5));
try {
$r->send();
if ($r->getResponseCode() == 200) {
$dir = $r->getResponseBody();
} else {
echo "Respose code " . $r->getResponseCode() . "({$url})\n";
echo $r->getResponseBody() . "({$url})\n";
return "-2";
}
} catch (HttpException $ex) {
echo $ex;
return "-3";
}
$dir = strip_tags($dir);
return explode("\n", $dir);
// An array of lines from the url
}
示例12: getCompetitionsPremierLeague
/**
* Permet d'avoir la liste de toutes les comp�titions.
* (Seul la Premier League est disponible avec un forfait gratuit)
* @return mixed
*/
public static function getCompetitionsPremierLeague()
{
$reqCometition = 'http://football-api.com/api/?Action=competitions&APIKey=' . self::API_KEY;
$reponse = new HttpRequest($reqCometition, HttpRequest::METH_GET);
try {
$reponse->send();
if ($reponse->getResponseCode() == 200) {
return json_decode($reponse->getResponseBody());
}
} catch (HttpException $ex) {
echo $ex;
}
}
示例13: request
private function request($method, Object $params = null)
{
$requestObj = new stdClass();
$requestObj->id = microtime(true);
$requestObj->method = $method;
$requestObj->params = $params;
$jsonRequest = json_encode($requestObj);
$timestamp = date("D d M Y H:i:s T");
$dt = new DateTime($timestamp, new DateTimeZone("CDT"));
$timestamp = Scalr_Util_DateTime::convertDateTime($dt, new DateTimeZone("UTC"), new DateTimeZone("CDT"))->format("D d M Y H:i:s");
$timestamp .= " UTC";
$canonical_string = $jsonRequest . $timestamp;
$signature = base64_encode(hash_hmac('SHA1', $canonical_string, $this->dbServer->GetProperty(SERVER_PROPERTIES::SZR_KEY), 1));
$request = new HttpRequest("http://{$this->dbServer->remoteIp}:{$this->port}/", HTTP_METH_POST);
$request->setOptions(array('timeout' => 5, 'connecttimeout' => 5));
$request->setHeaders(array("Date" => $timestamp, "X-Signature" => $signature, "X-Server-Id" => $this->dbServer->serverId));
$request->setRawPostData($jsonRequest);
try {
// Send request
$request->send();
if ($request->getResponseCode() == 200) {
$response = $request->getResponseData();
$jResponse = @json_decode($response['body']);
if ($jResponse->error) {
throw new Exception("{$jResponse->error->message} ({$jResponse->error->code}): {$jResponse->error->data}");
}
return $jResponse;
} else {
throw new Exception(sprintf("Unable to perform request to update client: %s", $request->getResponseCode()));
}
} catch (HttpException $e) {
if (isset($e->innerException)) {
$msg = $e->innerException->getMessage();
} else {
$msg = $e->getMessage();
}
throw new Exception(sprintf("Unable to perform request to update client: %s", $msg));
}
}
示例14: fetchData
private static function fetchData($station, $time, $lang, $timeSel)
{
//temporal public credentials for the NS API.
$url = "http://" . urlencode("pieter@appsforghent.be") . ":" . urlencode("fEoQropezniTJRw_5oKhGVlFwm_YWdOgozdMjSAVPLk3M3yZYKEa0A") . "@webservices.ns.nl/ns-api-avt?station=" . $station->name;
$r = new HttpRequest($url, HttpRequest::METH_GET);
try {
$r->send();
if ($r->getResponseCode() == 200) {
return new SimpleXMLElement($r->getResponseBody());
}
} catch (HttpException $ex) {
throw new Exception("Could not reach NS server", 500);
}
}
示例15: url
/**
* Static constructor
*
* @param string $url
* @param string $tmp
* @return BigGet
* @throws Exception
*/
public static function url($url, $tmp = '/tmp')
{
$head = new HttpRequest($url, HttpRequest::METH_HEAD);
$headers = $head->send()->getHeaders();
if (200 != $head->getResponseCode()) {
throw new HttpException("Did not receive '200 Ok' from HEAD {$url}");
}
if (!isset($headers['Accept-Ranges'])) {
throw new HttpException("Did not receive an Accept-Ranges header from HEAD {$url}");
}
if (!isset($headers['Content-Length'])) {
throw new HttpException("Did not receive a Content-Length header from HEAD {$url}");
}
$bigget = new BigGet();
$bigget->url = $url;
$bigget->tmp = tempnam($tmp, 'BigGet.');
$bigget->size = $headers['Content-Length'];
return $bigget;
}