本文整理汇总了PHP中Zend_Http_Client::request方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client::request方法的具体用法?PHP Zend_Http_Client::request怎么用?PHP Zend_Http_Client::request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Client
的用法示例。
在下文中一共展示了Zend_Http_Client::request方法的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: 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) {
}
}
示例3: _getXml
/**
* Given a url, use the provider to pull from the url
*
* @param $url
*
* @return string
*/
protected function _getXml($url)
{
if (is_null($this->_xmlProvider)) {
$this->setXmlProvider(new Varien_Http_Adapter_Curl());
}
$this->_client->setUri($url ? $url : 'http');
$response = $this->_client->request(Zend_Http_Client::GET);
return $response->getBody();
}
示例4: run
public function run()
{
if ($this->debugMode) {
echo "Restricting crawl to {$this->domain}\n";
}
//loop across available items in the queue of pages to crawl
while (!$this->queue->isEmpty()) {
if (isset($this->limit) && $this->counter >= $this->limit) {
break;
}
$this->counter++;
//get a new url to crawl
$url = $this->queue->pop();
if ($this->debugMode) {
echo "Queue Length: " . $this->queue->queueLength() . "\n";
echo "Crawling " . $url . "\n";
}
//set the url into the http client
$this->client->setUri($url);
//make the request to the remote server
$this->currentResponse = $this->client->request();
//don't bother trying to parse this if it's not text
if (stripos($this->currentResponse->getHeader('Content-type'), 'text') === false) {
continue;
}
//search for <a> tags in the document
$body = $this->currentResponse->getBody();
$linksQuery = new Zend_Dom_Query($body);
$links = $linksQuery->query('a');
if ($this->debugMode) {
echo "\tFound " . count($links) . " links...\n";
}
foreach ($links as $link) {
//get the href of the link and find out if it links to the current host
$href = $link->getAttribute('href');
$urlparts = parse_url($href);
if ($this->stayOnDomain && isset($urlparts["host"]) && $urlparts["host"] != $this->domain) {
continue;
}
//if it's an absolute link without a domain or a scheme, attempt to fix it
if (!isset($urlparts["host"])) {
$href = 'http://' . $this->domain . $href;
//this is a really naive way of doing this!
}
//push this link into the queue to be crawled
$this->queue->push($href);
}
//for each page that we see, run every registered task across it
foreach ($this->tasks as $task) {
$task->task($this->currentResponse, $this->client);
}
}
//after we're done with everything, call the shutdown hook on all the tasks
$this->shutdownTasks();
}
示例5: doSendInternalRequest
/**
* {@inheritdoc}
*/
protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
{
$this->client->resetParameters(true)->setConfig(array('httpversion' => $internalRequest->getProtocolVersion(), 'timeout' => $this->getConfiguration()->getTimeout(), 'maxredirects' => 0))->setUri($url = (string) $internalRequest->getUrl())->setMethod($internalRequest->getMethod())->setHeaders($this->prepareHeaders($internalRequest))->setRawData($this->prepareBody($internalRequest));
try {
$response = $this->client->request();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUrl($url, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse($response->getStatus(), $response->getMessage(), $response->getVersion(), $response->getHeaders(), BodyNormalizer::normalize(function () use($response) {
return $response instanceof \Zend_Http_Response_Stream ? $response->getStream() : $response->getBody();
}, $internalRequest->getMethod()));
}
示例6: sayRoom
public function sayRoom($room, $message, $type = 'TextMessage')
{
$uri = 'https://' . $this->subdomain . '.campfirenow.com/room/' . $room . '/speak.json';
$this->client->setUri($uri);
$params['message']['type'] = $type;
$params['message']['body'] = $message;
$this->client->setHeaders('Content-type', 'application/json');
$this->client->setRawData(json_encode($params));
$this->client->setMethod(Zend_Http_Client::POST);
$response = $this->client->request();
return (bool) ($response->getStatus() == 200);
}
示例7: _request
/**
* Осуществляет запроса к OpenId-провайдеру
*/
protected function _request()
{
try {
$responce = $this->_client->request($this->_options['method']);
$body = $responce->getBody();
} catch (Exception $e) {
throw new Exception('OpenId provider does not respond for request' . $this->_options['query'], '500');
}
$userData = $this->_normalizeUserData($body);
if (!$this->_isValid($userData)) {
throw new Exception('Error recieved from OpenId-provider', 500);
}
return $userData;
}
示例8: getData
public static function getData($url, $accesstoken, $redirects = true)
{
$client = new \Zend_Http_Client();
$client->setUri($url);
$client->setParameterGet('access_token', $accesstoken);
if ($redirects) {
$response = $client->request('GET')->getBody();
} else {
$client->setConfig(array('maxredirects' => 0));
$response = $client->request()->getHeader('Location');
$client->setConfig(array('maxredirects' => 5));
}
return $response;
}
示例9: request
/**
* Execute CheddarGetter API request
*
* @param string $url Url to the API action
* @param string $username Username
* @param string $password Password
* @param array|null $args HTTP post key value pairs
* @return string Body of the response from the CheddarGetter API
* @throws Zend_Http_Client_Exception A Zend_Http_Client_Exception may
* be thrown under a number of conditions but most likely if the tcp socket
* fails to connect.
*/
public function request($url, $username, $password, array $args = null)
{
// reset
$this->_client->setUri($url);
$this->_client->resetParameters();
$this->_client->setMethod(Zend_Http_Client::GET);
$this->_client->setAuth($username, $password);
if ($args) {
$this->_client->setMethod(Zend_Http_Client::POST);
$this->_client->setParameterPost($args);
}
$response = $this->_client->request();
return $response->getBody();
}
示例10: 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;
}
示例11: icsAction
public function icsAction()
{
$this->api_user = Mage::getModel('core/variable')->setStoreId(Mage::app()->getStore()->getId())->loadByCode('pmt_api_user')->getValue('text');
$this->api_password = Mage::getModel('core/variable')->setStoreId(Mage::app()->getStore()->getId())->loadByCode('pmt_api_password')->getValue('text');
// get prescription id
$prescriptionRepeatId = Mage::app()->getRequest()->getParam('id');
$customer = Mage::getSingleton('customer/session')->getCustomer();
$client = new Zend_Http_Client($this->api_get_prescripton_url . $prescriptionRepeatId);
$params = ['pmt_user_id' => $customer->getId(), 'prescription_repeat_id' => $prescriptionRepeatId];
// set some parameters
$client->setParameterPost($params);
$client->setAuth($this->api_user, $this->api_password, \Zend_Http_Client::AUTH_BASIC);
// POST request
$result = $client->request(Zend_Http_Client::POST);
// decode response
$jsonData = json_decode($result->getBody());
// var_dump($prescriptionRepeatId . $customer->getId());
// var_dump($result);
// exit();
if (!$jsonData->status == 'success') {
// create error message, before redirecting
// redirect to prescriptions page
$this->redirectDashboard();
}
$this->loadLayout();
$block = $this->getLayout()->getBlock('prescriptions_ics');
$block->assign(['repeat' => $jsonData->data->repeats[0], 'product' => $jsonData->data->prescription]);
$this->renderLayout();
}
示例12: translate
public function translate($message, $from, $to)
{
$url = "http://ajax.googleapis.com/ajax/services/language/translate";
$client = new Zend_Http_Client($url, array('maxredirects' => 0, 'timeout' => 30));
$langpair = $from . '|' . $to;
$params = array('v' => '1.1', 'q' => $message, 'langpair' => $langpair, 'key' => 'ABQIAAAAMtXAc56OizxVFR_fG__ZZRSrxD5q6_ZpfA55q8xveFjTjZJnShSvPHZq2PGkhSBZ0_OObHUNyy0smw');
/**
* Zend_Http_Client
*/
$client->setParameterPost($params);
$client->setHeaders('Referer', 'http://sb6.ru');
$response = $client->request("POST");
//print_r ($response);
$data = $response->getBody();
$serverResult = json_decode($data);
$status = $serverResult->responseStatus;
// should be 200
$result = '';
if ($status == 200) {
$result = $serverResult->responseData->translatedText;
} else {
echo "retry\n";
print_r($client->getLastRequest());
print_r($client->getLastResponse());
die;
return $this->translate($message, $from, $to);
}
return $result;
}
示例13: getContent
/**
* returns the content of this item
*
* @return string content
*/
public function getContent()
{
if ($this->items !== false && $this->valid()) {
try {
// load entry page
$client = new Zend_Http_Client($this->getLink() . '?page=all');
$response = $client->request();
$content = $response->getBody();
$content = utf8_decode($content);
// parse content
$dom = new Zend_Dom_Query($content);
$text = $dom->query('.article');
$innerHTML = '';
// convert innerHTML from DOM to string
// taken from http://us2.php.net/domelement (patrick smith)
$children = $text->current()->childNodes;
foreach ($children as $child) {
$tmp_doc = new DOMDocument();
$tmp_doc->appendChild($tmp_doc->importNode($child, true));
if (count($tmp_doc->getElementById('comments')) > 0) {
continue;
}
// convert to text
$innerHTML .= @$tmp_doc->saveHTML();
}
return $innerHTML;
} catch (Exception $e) {
// return default content
return current($this->items)->get_content();
}
}
}
示例14: execute
/**
* @see Console\Command\Command
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$supportSend = \SystemPref::get('support_send');
if ($supportSend) {
$stats = $this->getHelper('container')->getService('stat')->getAll();
$statsUrl = 'http://stat.sourcefabric.org';
$parameters = array('p' => 'newscoop');
$parameters['installation_id'] = $stats['installationId'];
$parameters['server'] = \SystemPref::get('support_stats_server');
$parameters['ip_address'] = \SystemPref::get('support_stats_ip_address');
$parameters['ram_used'] = $stats['ramUsed'];
$parameters['ram_total'] = \SystemPref::get('support_stats_ram_total');
$parameters['version'] = $stats['version'];
$parameters['install_method'] = $stats['installMethod'];
$parameters['publications'] = $stats['publications'];
$parameters['issues'] = $stats['issues'];
$parameters['sections'] = $stats['sections'];
$parameters['articles'] = $stats['articles'];
$parameters['articles_published'] = $stats['articlesPublished'];
$parameters['languages'] = $stats['languages'];
$parameters['authors'] = $stats['authors'];
$parameters['subscribers'] = $stats['subscribers'];
$parameters['backend_users'] = $stats['backendUsers'];
$parameters['images'] = $stats['images'];
$parameters['attachments'] = $stats['attachments'];
$parameters['topics'] = $stats['topics'];
$parameters['comments'] = $stats['comments'];
$parameters['hits'] = $stats['hits'];
$client = new \Zend_Http_Client();
$client->setUri($statsUrl);
$client->setParameterPost($parameters);
$response = $client->request('POST');
}
}
示例15: testZF4238FalseLinesInResponse
/**
* Test that lines that might be evaluated as boolean false do not break
* the reading prematurely.
*
* @see http://framework.zend.com/issues/browse/ZF-4238
*
*/
public function testZF4238FalseLinesInResponse()
{
$this->client->setUri($this->baseuri . 'ZF4238-zerolineresponse.txt');
$got = $this->client->request()->getBody();
$expected = $this->_getTestFileContents('ZF4238-zerolineresponse.txt');
$this->assertEquals($expected, $got);
}