本文整理汇总了PHP中HttpClient::setAuthorization方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpClient::setAuthorization方法的具体用法?PHP HttpClient::setAuthorization怎么用?PHP HttpClient::setAuthorization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient::setAuthorization方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preLogUser
function preLogUser($sessionId)
{
require_once AJXP_BIN_FOLDER . "/class.HttpClient.php";
$client = new HttpClient($this->getOption("REMOTE_SERVER"), $this->getOption("REMOTE_PORT"));
$client->setDebug(false);
if ($this->getOption("REMOTE_USER") != "") {
$client->setAuthorization($this->getOption("REMOTE_USER"), $this->getOption("REMOTE_PASSWORD"));
}
$client->setCookies(array($this->getOption("REMOTE_SESSION_NAME") ? $this->getOption("REMOTE_SESSION_NAME") : "PHPSESSID" => $sessionId));
$result = $client->get($this->getOption("REMOTE_URL"), array("session_id" => $sessionId));
if ($result) {
$user = $client->getContent();
if ($this->autoCreateUser()) {
AuthService::logUser($user, "", true);
} else {
// If not auto-create but the user exists, log him.
if ($this->userExists($user)) {
AuthService::logUser($user, "", true);
}
}
}
}
示例2: getRemoteConnexion
/**
* @return HttpClient
*/
public function getRemoteConnexion(&$remoteSecureToken, $refreshSessId = false, $repository = null)
{
require_once AJXP_BIN_FOLDER . "/class.HttpClient.php";
if ($repository != null) {
$crtRep = $repository;
} else {
$crtRep = ConfService::getRepository();
}
$httpClient = new HttpClient($crtRep->getOption("HOST"));
$httpClient->cookie_host = $crtRep->getOption("HOST");
$httpClient->timeout = 10;
if (isset($_SESSION["AJXP_REMOTE_SESSION"]) && is_array($_SESSION["AJXP_REMOTE_SESSION"])) {
$httpClient->setCookies($_SESSION["AJXP_REMOTE_SESSION"]);
}
//$httpClient->setDebug(true);
if (!isset($_SESSION["AJXP_REMOTE_SECURE_TOKEN"])) {
$httpClient->get($crtRep->getOption("URI") . "?get_action=get_secure_token");
$remoteSecureToken = $httpClient->getContent();
$_SESSION["AJXP_REMOTE_SECURE_TOKEN"] = $remoteSecureToken;
} else {
$remoteSecureToken = $_SESSION["AJXP_REMOTE_SECURE_TOKEN"];
}
if (!$crtRep->getOption("USE_AUTH")) {
return $httpClient;
}
$uri = "";
if ($crtRep->getOption("AUTH_URI") != "") {
$httpClient->setAuthorization($crtRep->getOption("AUTH_USER"), $crtRep->getOption("AUTH_PASS"));
$uri = $crtRep->getOption("AUTH_URI") . "?secure_token={$remoteSecureToken}";
}
if (!isset($_SESSION["AJXP_REMOTE_SESSION"]) || !is_array($_SESSION["AJXP_REMOTE_SESSION"]) || $refreshSessId) {
if ($uri == "") {
$this->logDebug("Remote_fs : relog necessary");
// Retrieve a seed!
$httpClient->get($crtRep->getOption("URI") . "?get_action=get_seed&secure_token={$remoteSecureToken}");
$seed = $httpClient->getContent();
$cookies = $httpClient->getCookies();
if (isset($cookies["AjaXplorer"])) {
$_SESSION["AJXP_REMOTE_SESSION"] = $cookies;
}
$user = $crtRep->getOption("AUTH_USER");
$pass = $crtRep->getOption("AUTH_PASS");
$pass = md5(md5($pass) . $seed);
$uri = $crtRep->getOption("URI") . "?get_action=login&userid=" . $user . "&password=" . $pass . "&login_seed={$seed}&secure_token={$remoteSecureToken}";
$httpClient->get($uri);
$content = $httpClient->getContent();
$matches = array();
if (preg_match_all('#.*?secure_token="(.*?)".*?#s', $content, $matches)) {
$remoteSecureToken = $matches[1][0];
$_SESSION["AJXP_REMOTE_SECURE_TOKEN"] = $remoteSecureToken;
}
$httpClient->setHeadersOnly(false);
} else {
$httpClient->setHeadersOnly(true);
$httpClient->get($uri);
$httpClient->setHeadersOnly(false);
}
$cookies = $httpClient->getCookies();
$_SESSION["AJXP_REMOTE_SESSION"] = $httpClient->getCookies();
} else {
$httpClient->setCookies($_SESSION["AJXP_REMOTE_SESSION"]);
}
return $httpClient;
}
示例3: getRemoteConnexion
/**
* @return HttpClient
*/
function getRemoteConnexion(&$remoteSessionId, $refreshSessId = false)
{
require_once INSTALL_PATH . "/server/classes/class.HttpClient.php";
$crtRep = ConfService::getRepository();
$httpClient = new HttpClient($crtRep->getOption("HOST"));
$httpClient->cookie_host = $crtRep->getOption("HOST");
$httpClient->timeout = 50;
//$httpClient->setDebug(true);
if ($crtRep->getOption("AUTH_URI") != "") {
$httpClient->setAuthorization($crtRep->getOption("AUTH_NAME"), $crtRep->getOption("AUTH_PASS"));
}
if (!isset($_SESSION["AJXP_REMOTE_SESSION"]) || $refreshSessId) {
$httpClient->setHeadersOnly(true);
$httpClient->get($crtRep->getOption("AUTH_URI"));
$httpClient->setHeadersOnly(false);
$cookies = $httpClient->getCookies();
if (isset($cookies["PHPSESSID"])) {
$_SESSION["AJXP_REMOTE_SESSION"] = $cookies["PHPSESSID"];
$remoteSessionId = $cookies["PHPSESSID"];
}
} else {
$remoteSessionId = $_SESSION["AJXP_REMOTE_SESSION"];
$httpClient->setCookies(array("PHPSESSID" => $remoteSessionId));
}
return $httpClient;
}
示例4: createHttpClient
/**
* Initialize and return the HttpClient
*
* @return HttpClient
*/
protected function createHttpClient()
{
require_once INSTALL_PATH . "/server/classes/class.HttpClient.php";
$httpClient = new HttpClient($this->host);
$httpClient->cookie_host = $this->host;
$httpClient->timeout = 50;
AJXP_Logger::debug("Creating Http client", array());
//$httpClient->setDebug(true);
if (!$this->use_auth) {
return $httpClient;
}
$uri = "";
if ($this->auth_path != "") {
$httpClient->setAuthorization($this->user, $this->password);
$uri = $this->auth_path;
}
if (!isset($_SESSION["AJXP_REMOTE_SESSION"])) {
if ($uri == "") {
// Retrieve a seed!
$httpClient->get($this->path . "?get_action=get_seed");
$seed = $httpClient->getContent();
$user = $this->user;
$pass = $this->password;
$pass = md5(md5($pass) . $seed);
$uri = $this->path . "?get_action=login&userid=" . $user . "&password=" . $pass . "&login_seed={$seed}";
}
$httpClient->setHeadersOnly(true);
$httpClient->get($uri);
$httpClient->setHeadersOnly(false);
$cookies = $httpClient->getCookies();
if (isset($cookies["AjaXplorer"])) {
$_SESSION["AJXP_REMOTE_SESSION"] = $cookies["AjaXplorer"];
$remoteSessionId = $cookies["AjaXplorer"];
}
} else {
$remoteSessionId = $_SESSION["AJXP_REMOTE_SESSION"];
$httpClient->setCookies(array("AjaXplorer" => $remoteSessionId));
}
AJXP_Logger::debug("Http Client created", array());
return $httpClient;
}
示例5: getRemoteConnexion
/**
* @return HttpClient
*/
function getRemoteConnexion(&$remoteSessionId, $refreshSessId = false)
{
require_once INSTALL_PATH . "/server/classes/class.HttpClient.php";
$crtRep = ConfService::getRepository();
$httpClient = new HttpClient($crtRep->getOption("HOST"));
$httpClient->cookie_host = $crtRep->getOption("HOST");
$httpClient->timeout = 10;
//$httpClient->setDebug(true);
if (!$crtRep->getOption("USE_AUTH")) {
return $httpClient;
}
$uri = "";
if ($crtRep->getOption("AUTH_URI") != "") {
$httpClient->setAuthorization($crtRep->getOption("AUTH_USER"), $crtRep->getOption("AUTH_PASS"));
$uri = $crtRep->getOption("AUTH_URI");
}
if (!isset($_SESSION["AJXP_REMOTE_SESSION"]) || $refreshSessId) {
if ($uri == "") {
// Retrieve a seed!
$httpClient->get($crtRep->getOption("URI") . "?get_action=get_seed");
$seed = $httpClient->getContent();
$user = $crtRep->getOption("AUTH_USER");
$pass = $crtRep->getOption("AUTH_PASS");
$pass = md5(md5($pass) . $seed);
$uri = $crtRep->getOption("URI") . "?get_action=login&userid=" . $user . "&password=" . $pass . "&login_seed={$seed}";
}
$httpClient->setHeadersOnly(true);
$httpClient->get($uri);
$httpClient->setHeadersOnly(false);
$cookies = $httpClient->getCookies();
if (isset($cookies["AjaXplorer"])) {
$_SESSION["AJXP_REMOTE_SESSION"] = $cookies["AjaXplorer"];
$remoteSessionId = $cookies["AjaXplorer"];
}
} else {
$remoteSessionId = $_SESSION["AJXP_REMOTE_SESSION"];
$httpClient->setCookies(array("AjaXplorer" => $remoteSessionId));
}
return $httpClient;
}
示例6: quickPostAuthorization
function quickPostAuthorization($url, $data,$username,$pw) {
$bits = parse_url($url);
$host = $bits['host'];
$port = isset($bits['port']) ? $bits['port'] : 80;
$path = isset($bits['path']) ? $bits['path'] : '/';
$client = new HttpClient($host, $port);
$client->setAuthorization($username,$pw);
if (!$client->post($path, $data)) {
return false;
} else {
return $client->getContent();
}
}