本文整理汇总了PHP中HttpClient::setCookies方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpClient::setCookies方法的具体用法?PHP HttpClient::setCookies怎么用?PHP HttpClient::setCookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient::setCookies方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: core_call
public function core_call($serialized_request)
{
$client = new HttpClient($this->domain);
$client->setCookies($this->cookies);
$client->post($this->location . "json/", $serialized_request);
return $client->getContent();
}
示例2: 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);
}
}
}
}
示例3: customHttpClient
function customHttpClient($SERVER, $PATH, $COOKIES, $PARAMS)
{
//return;//return '{"resHeader":{"backUrl":"","flag":"0","msg":"访问失败"}}';
//到远程服务器查询登录状态
include_once dirname(__FILE__) . '/httpclient.inc.php';
try {
$client = new HttpClient($SERVER);
$client->timeout = 10;
$client->setCookies($COOKIES);
$client->setPersistCookies(true);
$postURL = $PATH;
customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", getHexDecode($client->buildQueryString($PARAMS)));
if (!$client->post($postURL, $PARAMS)) {
customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", "\nPUT SERVER:" . $SERVER . "" . $PATH . "\nFAILD1");
return '{"resHeader":{"backUrl":"","flag":"0","msg":"访问失败1"}}';
}
} catch (Exception $e) {
customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", "\nPUT SERVER:" . $SERVER . "" . $PATH . "\nFAILD2");
return '{"resHeader":{"backUrl":"","flag":"0","msg":"访问失败2"}}';
}
$response = $client->getContent();
customCreateLogFile(dirname(__FILE__) . "/httpclient_log/" . date('Ymd') . ".txt", "\nPUT SERVER:" . $SERVER . "" . $PATH . "\nPUT COOKIES:" . (is_array($COOKIES) ? var_export($COOKIES, true) : '') . "\nPUT DATA:" . (is_array($PARAMS) ? var_export($PARAMS, true) : $PARAMS) . "\nGET DATA:" . iconv('GBK', 'UTF-8', $response));
return iconv('GBK', 'UTF-8', $response);
}
示例4: 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;
}
示例5: drupal_remote_auth
function drupal_remote_auth($host, $uri, $login, $pass, $formId = "")
{
$client = new HttpClient($host);
$client->setHandleRedirects(false);
$res = $client->get($uri);
$content = $client->getContent();
$xmlDoc = DOMDocument::loadHTML($content);
$xPath = new DOMXPath($xmlDoc);
if ($formId == "") {
$formId = "user-login-form";
}
$nodes = $xPath->query('//form[@id="' . $formId . '"]');
if (!$nodes->length) {
return "";
}
$form = $nodes->item(0);
$postUri = $form->getAttribute("action");
$hiddens = $xPath->query('//input[@type="hidden"]', $form);
AJXP_Logger::debug("Carry on Drupal hiddens " . $hiddens->length);
$postData = array("name" => $login, "pass" => $pass, "Submit" => "Log in");
foreach ($hiddens as $hiddenNode) {
$postData[$hiddenNode->getAttribute("name")] = $hiddenNode->getAttribute("value");
}
$client->setHandleRedirects(false);
$client->setHeadersOnly(true);
$client->setCookies(extractResponseCookies($client));
$res2 = $client->post($postUri, $postData);
$newCookies = extractResponseCookies($client);
if (isset($newCookies["AjaXplorer"])) {
return $newCookies["AjaXplorer"];
}
return "";
}
示例6: 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;
}
示例7: main
function main($subDir, $class, $cookieURL, $indexURL, $totalClass, $curClass, $code)
{
$isSleep = true;
makeDir("./html/{$subDir}/{$class}/");
$dataFileName = "data/{$subDir}/{$class}.log";
$httpClient = new HttpClient("epub.cnki.net");
$content = "";
$indexFname = "./html/{$subDir}/{$class}/index.html";
$tf = iconv("utf-8", "gb2312", $indexFname);
$cookies = "";
if (file_exists($tf)) {
$isSleep = false;
$content = file_get_contents($tf);
echo "From cache get index.....\n";
} else {
/*获取并设置cookie*/
$httpClient->get($cookieURL);
$cookies = $httpClient->getCookies();
$httpClient->setCookies($cookies);
if (!$cookies) {
die("cookie error");
}
$isSleep = true;
$httpClient->get($indexURL);
$content = $httpClient->getContent();
save($indexFname, $content);
//保存
echo "save index file...\n";
}
/* 解析出一共有多少页面 */
$pageCount = parsePageCount($content);
echo "Page is {$pageCount} ****\n";
$articleCount = ARTICLE_PRE_PAGE * $pageCount;
//计算一共有多少篇文章,大于等于实际文章数目,不影响结果
echo "total article is {$articleCount}\n";
$pageCount = $articleCount / ARTICLE_PRE_PAGE;
$pageCount = ceil($pageCount);
//向上取整,不放过任何数据
if ($pageCount == 0) {
$pageCount = 1;
}
if ($pageCount > 50) {
echo "page count is big than 50\n";
}
echo "total page of {$class} is : {$pageCount}...............{$curClass} of {$totalClass}\n";
if ($isSleep) {
fakeSleep();
}
/* 抓取每一个页面并且保存下来,保存的同时进行解析 */
for ($i = 1; $i <= $pageCount; $i++) {
$content = NULL;
$pageI = getPageI($indexURL, $i);
//第i页的地址
$htmlI = "./html/{$subDir}/{$class}/{$i}.html";
if (!file_exists(iconv("utf-8", "gb2312", $htmlI))) {
$isSleep = true;
$httpClient->setCookies($cookies);
$httpClient->get($pageI);
$content = $httpClient->getContent();
save($htmlI, $content);
echo "From newwork & save {$i}.html..........[{$i} of {$pageCount}]\n";
} else {
$tmpf2 = iconv("utf-8", "gb2312", $htmlI);
$content = file_get_contents($tmpf2);
$ok = validatePageContent($content);
//是否出现了验证码
if (!$ok) {
$i = $i - 1;
delFile($htmlI);
} else {
$isSleep = false;
echo "Find local file {$htmlI} & skip\n";
}
//continue;
}
$logName = "./data/{$subDir}/{$class}.log";
if (!validatePageContent($content)) {
$i = $i - 1;
delFile($htmlI);
dosleep(60);
$httpClient = new HttpClient("epub.cnki.net");
$httpClient->get($cookieURL);
$cookies = $httpClient->getCookies();
$httpClient->setCookies($cookies);
continue;
}
parseContent($content, $logName, $code);
if ($i != $pageCount && $isSleep) {
fakeSleep();
} else {
echo "+\n";
echo "+\n";
echo "+ {$class} done\n";
echo "+\n";
echo "+\n";
}
}
}
示例8: 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;
}
示例9: 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;
}
示例10: quickUpload
static function quickUpload($url, $files, $data, $cks = array(), $time = 300)
{
$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->path = $path;
$client->setCookies($cks);
$client->timeout = $time;
if (!$client->upload($files, $data)) {
unset($client);
return false;
} else {
$res = $client->getContent(true);
unset($client);
return $res;
}
}
示例11: getCookieURL
if (!file_exists($localedCachedHtml)) {
$sleep = true;
echo "Miss!\n";
$cookieURL = getCookieURL($code);
/*获取并设置cookie*/
$cookies = $httpClient->getCookies();
if (!$cookies) {
do {
$httpClient->get($cookieURL);
$cookies = $httpClient->getCookies();
if (!$cookies) {
$sc = 30;
echo "Cookie是空的,睡眠{$sc} S\n";
sleep($sc);
} else {
$httpClient->setCookies($cookies);
}
// $httpClient->get($cookieURL);
// $cookies = $httpClient->getCookies();
} while (!$cookies);
}
$httpClient->setReferer($refUrl);
$contentUrl = "http://epub.cnki.net" . $u;
$contentSize = 0;
do {
$httpClient->get($contentUrl);
$content = $httpClient->getContent();
//302页面
/*解析地址*/
$contentUrl = get_content_url($content);
echo $contentUrl . "\n";
示例12: send
private static function send($url, $cookies, RequestSet $set, $cookieTable)
{
$bits = parse_url($url);
$host = $bits['host'];
$port = isset($bits['port']) ? $bits['port'] : 80;
$path = isset($bits['path']) ? $bits['path'] : '/';
$conn = new HttpClient($host, $port);
$conn->setCookies($cookieTable);
$conn->setContentType("text/xml;charset=UTF-8");
// Output ...
$xml = $set->toXMLString();
if (!$conn->post($path, $xml)) {
throw new Exception("PLLClient send exception");
}
// Input ...
$in_string = $conn->getContent();
$cookieTable = $conn->getCookies();
$resset = ResponseSet::parseXML($in_string);
return $resset->getResponses();
}
示例13: weixin_bind
private function weixin_bind($username, $password)
{
// echo 555;exit;
$new_token = md5($username . $password);
$new_token = substr($new_token, 2, 15);
import("@.ORG.HttpClient");
$http = new HttpClient('mp.weixin.qq.com');
$http->setPersistCookies(true);
$http->setPersistReferers(true);
$http->setCookies(array('uin_cookie' => '85858963', 'euin_cookie' => 'A6C9D89A295536D698C6446BEBE935C403FA57F2166E6962', 'ac' => '1,008,009'));
$http->get('/');
$http->post('/cgi-bin/login', array('f' => 'json', 'imgcode' => '', 'username' => $username, 'pwd' => md5($password)));
$sres = trim($http->getContent(true));
$reds = json_decode($sres);
$token = $reds->ErrMsg;
$token = explode('&token=', $token);
$token = $token[1];
//关闭普通接口
$http->post('/cgi-bin/skeyform?form=advancedswitchform&lang=zh_CN', array('flag' => '0', 'type' => '1', 'token' => $token));
$http->getContent(true);
//修改开发路径
$http->post('/cgi-bin/callbackprofile?t=ajax-response&lang=zh_CN&token=' . $token, array('url' => C('site_url') . '/index.php/api/' . $new_token, 'callback_token' => $new_token));
$res = $http->getContent(true);
sleep(1);
//开启开发接口
$http->post('/cgi-bin/skeyform?form=advancedswitchform&lang=zh_CN', array('flag' => '1', 'type' => '2', 'token' => $token));
$http->getContent(true);
//获取用户微信基本信息
$http->get('/cgi-bin/settingpage?t=setting/index&action=index&token=' . $token . '&lang=zh_CN');
$setting = $http->getContent(true);
preg_match('|<li class="account_setting_item">.*?名称.*?<div class="meta_content">(.*?)</div>.*?</li>.*?<li class="account_setting_item">.*?原始ID.*?<div class="meta_content">.*?<span>(.*?)</span>.*?</div>.*?</li>.*?<li class="account_setting_item">.*?微信号.*?<div class="meta_content">.*?<span>(.*?)</span>.*?</div>.*?</li>|is', $setting, $baseinfo);
if (trim($baseinfo[1])) {
$resut = array('wxname' => trim($baseinfo[1]), 'wxid' => trim($baseinfo[2]), 'weixin' => trim($baseinfo[3]), 'token' => $new_token);
} else {
$resut = array();
}
return $resut;
}