本文整理汇总了PHP中Zend_Http_Client::setCookieJar方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client::setCookieJar方法的具体用法?PHP Zend_Http_Client::setCookieJar怎么用?PHP Zend_Http_Client::setCookieJar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Client
的用法示例。
在下文中一共展示了Zend_Http_Client::setCookieJar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: logout
public static function logout()
{
$blogPath = SJB_Settings::getSettingByName('blog_path');
if (empty($blogPath)) {
return;
}
$url = SJB_System::getSystemSettings('SITE_URL') . $blogPath . '/';
$client = new Zend_Http_Client($url, array('useragent' => SJB_Request::getUserAgent(), 'maxredirects' => 0));
if (isset($_SESSION['wp_cookie_jar'])) {
$client->setCookieJar(@unserialize($_SESSION['wp_cookie_jar']));
}
try {
$response = $client->request();
$matches = array();
if (preg_match('/_wpnonce=([\\w\\d]+)"/', $response->getBody(), $matches)) {
$wpnonce = $matches[1];
$url = $url . 'wp-login.php?action=logout&_wpnonce=' . $wpnonce . '&noSJB=1';
$client->setUri($url);
$response = $client->request();
foreach ($response->getHeaders() as $key => $header) {
if ('set-cookie' == strtolower($key)) {
if (is_array($header)) {
foreach ($header as $val) {
header("Set-Cookie: " . $val, false);
}
} else {
header("Set-Cookie: " . $header, false);
}
}
}
}
} catch (Exception $ex) {
}
}
示例2: _fetch
/**
* Fetches the contents of a URL.
*
* @param string $url
* @param bool $useCookieJar
* @param bool $ignoreHttpError
* @return string
* @throws Yadda_Feed_Exception
*/
protected function _fetch($url, $useCookieJar = false, $ignoreHttpError = false)
{
$config = Zend_Registry::get('config');
$retries = 3;
// try 3 times
$client = new Zend_Http_Client($url, array('timeout' => 30, 'useragent' => $config->userAgent));
if ($useCookieJar === true) {
$client->setCookieJar(true);
}
for ($i = 0; $i < $retries; $i++) {
try {
$response = $client->request();
if ((bool) $ignoreHttpError === false) {
if ($response->getStatus() != 200) {
throw new Zend_Http_Exception('Didn\'t get 200 OK.');
}
}
// request was successful, so break out of retry loop
break;
} catch (Zend_Exception $e) {
// if we're on the last retry, throw an exception
if ($i == $retries - 1) {
throw new Yadda_Feed_Exception('Error fetching URL: ' . (string) $e);
}
}
// retry!
sleep(1);
}
return $response->getBody();
}
示例3: wrapper_getFirstImageFromContent
function wrapper_getFirstImageFromContent($section_id, $exec_droplets = true)
{
global $database;
$settings = $database->query(sprintf('SELECT `url` FROM `%smod_wrapper` WHERE section_id = "%d"', CAT_TABLE_PREFIX, $section_id));
if ($settings->numRows()) {
$row = $settings->fetchRow();
ini_set('include_path', CAT_PATH . '/modules/lib_zendlite');
include 'Zend/Http/Client.php';
$client = new Zend_Http_Client($row['url'], array('timeout' => '30', 'adapter' => 'Zend_Http_Client_Adapter_Proxy'));
$client->setCookieJar();
$client->setHeaders(array('Pragma' => 'no-cache', 'Cache-Control' => 'no-cache', 'Accept-Encoding' => ''));
try {
$response = $client->request(Zend_Http_Client::GET);
if ($response->getStatus() == '200') {
$content = $response->getBody();
if ($content != '') {
$doc = new DOMDocument();
libxml_use_internal_errors(true);
// avoid HTML5 errors
$doc->loadHTML($content);
libxml_clear_errors();
$img = $doc->getElementsByTagName('img');
return $img->item(0)->getAttribute('src');
}
}
} catch (Zend_HTTP_Client_Adapter_Exception $e) {
}
return NULL;
}
}
示例4: logout
static function logout()
{
SessionStorage::destroy(SJB_Session::getSessionId());
$forumPath = SJB_Settings::getSettingByName('forum_path');
if (empty($forumPath)) {
return;
}
$url = SJB_System::getSystemSettings('SITE_URL') . $forumPath . '/';
$client = new Zend_Http_Client($url, array('useragent' => SJB_Request::getUserAgent()));
$client->setCookie($_COOKIE);
$client->setCookieJar();
try {
$response = $client->request();
$matches = array();
if (preg_match('/\\.\\/ucp.php\\?mode=logout\\&sid=([\\w\\d]+)"/', $response->getBody(), $matches)) {
$sid = $matches[1];
$client->setUri($url . 'ucp.php?mode=logout&sid=' . $sid);
$response = $client->request();
foreach ($response->getHeaders() as $key => $header) {
if ('set-cookie' == strtolower($key)) {
if (is_array($header)) {
foreach ($header as $val) {
header("Set-Cookie: " . $val, false);
}
} else {
header("Set-Cookie: " . $header, false);
}
}
}
}
} catch (Exception $ex) {
}
}
示例5: getHttpClient
/**
* @return Zend_Http_Client
*/
protected function getHttpClient($url = null)
{
if ($this->http === null) {
$this->http = new Zend_Http_Client();
// maybe it's better to offuscate it
//$this->http->setHeaders('User-Agent', "vlc-shares/".X_VlcShares::VERSION." hulu/".X_VlcShares_Plugins_Hulu::VERSION);
$this->http->setHeaders(array('User-Agent' => 'Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0)', 'Accept' => '*/*'));
// enable cookies
$this->http->setCookieJar(true);
/*
$this->http->setAdapter("Zend_Http_Client_Adapter_Proxy");
$this->http->setConfig(array(
//'proxy_host' => "141.219.252.132",
//'proxy_port' => '3128'
//'proxy_host' => '131.179.150.72',
//'proxy_port' => '3128',
//'proxy_host' => '129.82.12.188',
//'proxy_port' => '3128',
//'proxy_host' => '130.49.221.40',
//'proxy_port' => '3128',
'proxy_host' => '65.55.73.222',
'proxy_port' => '80'
));
*/
}
if ($url !== null) {
$this->http->setUri($url);
}
return $this->http;
}
示例6: testSetInvalidCookieJar
/**
* Make sure using an invalid cookie jar object throws an exception
*
*/
public function testSetInvalidCookieJar()
{
$this->setExpectedException(
'Zend\Http\Client\Exception\InvalidArgumentException',
'Invalid parameter type passed as CookieJar');
$this->_client->setCookieJar('cookiejar');
}
示例7: testSetInvalidCookieJar
/**
* Make sure using an invalid cookie jar object throws an exception
*
*/
public function testSetInvalidCookieJar()
{
try {
$this->client->setCookieJar('cookiejar');
$this->fail('Invalid cookiejar exception was not thrown');
} catch (Exception $e) {
// We're good
}
}
示例8: __construct
public function __construct($uri, $email, $password, $consumer_key, $consumer_secret, $oauth_realm, $cookieJarFile = './OX3_Api_CookieJar.txt', $sso = array(), $proxy = array())
{
parent::__construct($uri);
$aUrl = parse_url($uri);
if (empty($sso)) {
$sso = array('siteUrl' => 'https://sso.openx.com/api/index/initiate', 'requestTokenUrl' => 'https://sso.openx.com/api/index/initiate', 'accessTokenUrl' => 'https://sso.openx.com/api/index/token', 'authorizeUrl' => 'https://sso.openx.com/login/login', 'loginUrl' => 'https://sso.openx.com/login/process');
}
// Set the proxy['adapter'] if $proxy config was passed in
if (!empty($proxy)) {
$proxy['adapter'] = 'Zend_Http_Client_Adapter_Proxy';
}
// Initilize the cookie jar, from the $cookieJarFile if present
$client = self::getHttpClient();
$cookieJar = false;
if (is_readable($cookieJarFile)) {
$cookieJar = @unserialize(file_get_contents($cookieJarFile));
}
if (!$cookieJar instanceof Zend_Http_CookieJar) {
$cookieJar = new Zend_Http_CookieJar();
}
$client->setCookieJar($cookieJar);
$client->setConfig($proxy);
$result = $this->put('/a/session/validate');
// See if the openx3_access_token is still valid...
if ($result->isError()) {
// Get Request Token
$config = array('siteUrl' => $sso['siteUrl'], 'requestTokenUrl' => $sso['requestTokenUrl'], 'accessTokenUrl' => $sso['accessTokenUrl'], 'authorizeUrl' => $sso['authorizeUrl'], 'consumerKey' => $consumer_key, 'consumerSecret' => $consumer_secret, 'realm' => $oauth_realm);
$oAuth = new OX3_Oauth_Consumer($config);
$requestToken = $oAuth->getRequestToken();
// Authenticate to SSO
$loginClient = new Zend_Http_Client($sso['loginUrl']);
$loginClient->setCookieJar();
$loginClient->setConfig($proxy);
$loginClient->setParameterPost(array('email' => $email, 'password' => $password, 'oauth_token' => $requestToken->getToken()));
$loginClient->request(Zend_Http_Client::POST);
$loginBody = $loginClient->getLastResponse()->getBody();
// Parse response, sucessful headless logins will return oob?oauth_token=<token>&oauth_verifier=<verifier> as the body
if (substr($loginBody, 0, 4) == 'oob?') {
$vars = array();
@parse_str(substr($loginBody, 4), $vars);
if (empty($vars['oauth_token'])) {
throw new Exception('Error parsing SSO login response');
}
// Swap the (authorized) request token for an access token:
$accessToken = $oAuth->getAccessToken($vars, $requestToken)->getToken();
$client->setCookie(new Zend_Http_Cookie('openx3_access_token', $accessToken, $aUrl['host']));
$result = $this->put('/a/session/validate');
if ($result->isSuccessful()) {
file_put_contents($cookieJarFile, serialize($client->getCookieJar()), LOCK_EX);
chmod($cookieJarFile, 0666);
}
} else {
throw new Exception('SSO Authentication error');
}
}
}
示例9: _initHttpClient
/**
* Initializes the HTTP client object.
*
* @return Zend_Http_Client
*/
protected function _initHttpClient()
{
$serverUri = $this->getOption('server_uri');
if (!$serverUri) {
throw new AcApi_Transport_Adapter_Exception('No server URI set.');
}
try {
$client = new Zend_Http_Client($serverUri);
} catch (Zend_Uri_Exception $e) {
throw new AcApi_Transport_Exception(sprintf("%s '%s'", $e->getMessage(), $serverUri));
}
$client->setCookieJar();
return $client;
}
示例10: testSetCookieObjectJar
/**
* Make sure we can set cookie objects with a jar
*
*/
public function testSetCookieObjectJar()
{
$this->client->setUri($this->baseuri . 'testCookies.php');
$this->client->setCookieJar();
$refuri = $this->client->getUri();
$cookies = array(Zend_Http_Cookie::fromString('chocolate=chips', $refuri), Zend_Http_Cookie::fromString('crumble=apple', $refuri));
$strcookies = array();
foreach ($cookies as $c) {
$this->client->setCookie($c);
$strcookies[$c->getName()] = $c->getValue();
}
$res = $this->client->request();
$this->assertEquals($res->getBody(), serialize($strcookies), 'Response body does not contain the expected cookies');
}
示例11: _request
/**
*
* @param string $url
* @param array $param
* @param string $method
* @return string
*/
protected function _request($url, $param = array(), $method = Zend_Http_Client::POST)
{
if ($this->_client === null) {
$config = array('useragent' => 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/44.0', 'encodecookies' => false, 'timeout' => 180);
$this->_client = new Zend_Http_Client($url, $config);
$this->_client->setCookieJar();
}
$this->_client->resetParameters()->setUri($url);
if (count($param['post']) > 0) {
foreach ($param['post'] as $name => $value) {
$this->_client->setParameterPost($name, $value);
}
}
if (count($param['get']) > 0) {
foreach ($param['get'] as $name => $value) {
$this->_client->setParameterPost($name, $value);
}
}
if (count($param['file']) > 0) {
foreach ($param['file'] as $name => $value) {
$this->_client->setFileUpload($value, $name);
}
}
if (count($param['cookie']) > 0) {
foreach ($param['cookie'] as $name => $value) {
$this->_client->setCookie($name, $value);
}
}
if (count($this->_cookies) > 0) {
foreach ($this->_cookies as $cookie) {
$this->_client->setCookie($cookie);
}
}
$response = $this->_client->request($method);
$this->_cookies = $this->_client->getCookieJar()->getAllCookies();
return $response->getBody();
}
示例12: getHttpClient
/**
*
* @return Zend_Http_Client
*/
public function getHttpClient()
{
if (is_null($this->httpClient)) {
$config = array('adapter' => 'Zend_Http_Client_Adapter_Proxy', 'useragent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31', 'timeout' => 30);
$headers = array('Referer' => $this->uriStartPage, 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'Accept-Encoding' => 'gzip,deflate', 'Accept-Language' => 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4', 'DNT' => '1');
if (function_exists('curl_exec') && is_callable('curl_exec')) {
$config['adapter'] = 'Zend_Http_Client_Adapter_Curl';
}
$client = new Zend_Http_Client(null, $config);
$client->setCookieJar();
$client->setHeaders($headers);
$this->httpClient = $client;
}
return $this->httpClient;
}
示例13: getPlayableInfos
/**
* get an array with standard information about the playable
* @param string $url the hoster page or resource ID
* @param boolean $isId
* @return array format:
* array(
* 'title' => TITLE
* 'description' => DESCRIPTION
* 'length' => LENGTH
* ...
* )
*/
function getPlayableInfos($url, $isId = true)
{
if (!$isId) {
$url = $this->getResourceId($url);
}
// use cached values
if (array_key_exists($url, $this->info_cache)) {
return $this->info_cache[$url];
}
// use the api
$http = new Zend_Http_Client("http://www.movshare.net/video/{$url}", array('headers' => array('User-Agent' => "vlc-shares/" . X_VlcShares::VERSION . " movshare/" . X_VlcShares_Plugins_MovShare::VERSION)));
// this allow to store the cookie for multiple requests
$http->setCookieJar(true);
$datas = $http->request()->getBody();
if (strpos($datas, 'We need you to prove you\'re human') !== false) {
// I have to do the request, again
$datas = $http->request()->getBody();
if (strpos($datas, 'We need you to prove you\'re human') !== false) {
throw new Exception("Hoster requires interaction");
}
}
// now datas should contains the html
// time to grab some informations
if (strpos($datas, 'This file no longer exists on our servers') !== false) {
throw new Exception("Invalid ID {{$url}}", self::E_ID_INVALID);
}
$matches = array();
if (!preg_match('/Title\\: <\\/strong>(?P<title>[^\\<]+)</', $datas, $matches)) {
$title = "";
}
$title = $matches['title'];
$matches = array();
if (!preg_match('/Description\\: <\\/strong>(?P<description>[^\\<]+)</', $datas, $matches)) {
$description = '';
}
$description = $matches['description'];
$length = 0;
$thumbnail = '';
$matches = array();
if (!preg_match('/param name\\=\\"src\\" value\\=\\"(?P<video>[^\\"]+)\\"/', $datas, $matches)) {
$video = '';
}
$video = $matches['video'];
$infos = array('title' => $title, 'description' => $description, 'length' => $length, 'thumbnail' => $thumbnail, 'url' => $video);
// add in cache
$this->info_cache[$url] = $infos;
return $infos;
}
示例14: getPlayableInfos
/**
* get an array with standard information about the playable
* @param string $url the hoster page or resource ID
* @param boolean $isId
* @return array format:
* array(
* 'title' => TITLE
* 'description' => DESCRIPTION
* 'length' => LENGTH
* ...
* )
*/
function getPlayableInfos($url, $isId = true)
{
if (!$isId) {
$url = $this->getResourceId($url);
}
// use cached values
if (array_key_exists($url, $this->info_cache)) {
return $this->info_cache[$url];
}
$http = new Zend_Http_Client("http://www.dailymotion.com/video/" . $url, array('headers' => array('User-Agent' => "vlc-shares/" . X_VlcShares::VERSION . " dailymotion/" . X_VlcShares_Plugins_DailyMotion::VERSION)));
$http->setCookieJar(true);
$http->getCookieJar()->addCookie(new Zend_Http_Cookie('family_filter', 'off', 'www.dailymotion.com'));
$datas = $http->request()->getBody();
if (preg_match('/<title>(.*)404(.*)<\\/title>/', $datas)) {
throw new Exception("Invalid ID {{$url}}", self::E_ID_INVALID);
}
$matches = array();
if (!preg_match('/\\.addVariable\\(\\"sequence\\", \\"(?P<sequence>.*?)\\"/', $datas, $matches)) {
throw new Exception("Invalid ID {{$url}}, sequence not found", self::E_ID_INVALID);
}
$sequence = urldecode($matches['sequence']);
$matches = array();
if (!preg_match('/videotitle\\=(?P<title>[^&]+)&/', $sequence, $matches)) {
$title = "";
}
$title = urldecode($matches['title']);
$matches = array();
if (!preg_match('/\\"videoDescription\\"\\:\\"(?P<description>[^\\"]*)\\"/', $sequence, $matches)) {
$description = '';
}
$description = urldecode($matches['description']);
$matches = array();
if (!preg_match('/\\"duration\\"\\:(?P<length>.*)\\,/', $sequence, $matches)) {
$length = '';
}
$length = $matches['length'];
$thumbnail = "http://www.dailymotion.com/thumbnail/320x240/video/{$url}";
$matches = array();
if (!preg_match('/\\"sdURL\\"\\:\\"(?P<video>[^\\"]+)\\"/', $sequence, $matches)) {
$video = '';
}
$video = stripslashes($matches['video']);
$infos = array('title' => $title, 'description' => $description, 'length' => $length, 'thumbnail' => $thumbnail, 'url' => $video);
// add in cache
$this->info_cache[$url] = $infos;
return $infos;
}
示例15: array
function __construct($parserType, $config = array(), $url = null)
{
// Create Zend_Http_Client object
$this->client = new Zend_Http_Client($url);
// attach a new cookie jar to your Zend_Http_Client object
$this->client->setCookieJar();
// Сохраним последнюю конфигурацию
$this->last_config = $this->_setConfig($config);
// Last URL
if ($url) {
$this->last_url = $url;
}
// Set parser type
if ($parserType) {
$this->parserType = $parserType;
}
}