本文整理汇总了PHP中Zend_Http_Client::getLastResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client::getLastResponse方法的具体用法?PHP Zend_Http_Client::getLastResponse怎么用?PHP Zend_Http_Client::getLastResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Client
的用法示例。
在下文中一共展示了Zend_Http_Client::getLastResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: send
public function send()
{
$me = new self("global");
$sent = array();
$textlink = new Feed_TextLink();
$feed = $textlink->feed();
$items = array();
//we send something only if we have something to send
if (empty($feed->feed->entry) == false) {
foreach ($feed->feed->entry as &$item) {
if (empty($item->forwardlink->href) || isset($sent[$item->forwardlink->hash])) {
continue;
}
$sent[$item->forwardlink->hash] = true;
$client = new Zend_Http_Client($item->forwardlink->href, array('timeout' => 60));
if (!empty($feed->feed->entry)) {
$client->setParameterPost(array('protocol' => 'forwardlink', 'contribution' => json_encode($feed)));
try {
$response = $client->request(Zend_Http_Client::POST);
$request = $client->getLastResponse();
$result = $response->getBody();
$resultJson = json_decode($response->getBody());
//Here we add the date last updated so that we don't have to send it if not needed, saving load time.
if (!empty($resultJson->feed) && $resultJson->feed == "success") {
$me->addItem(array('dateLastUpdated' => $item->textlink->dateLastUpdated, 'textlinkHash' => $item->textlink->hash, 'forwardlinkHash' => $item->forwardlink->hash));
}
$items[$item->textlink->text] = $result;
} catch (Exception $e) {
}
}
}
return $items;
}
}
示例3: validate
/**
* Validate the license information
*
* @param string $userId
* @param array $spMetadata
* @param array $idpMetadata
* @return string
*/
public function validate($userId, array $spMetadata, array $idpMetadata)
{
if (!$this->_active) {
return EngineBlock_LicenseEngine_ValidationManager::LICENSE_UNKNOWN;
}
$client = new Zend_Http_Client($this->_url);
$client->setConfig(array('timeout' => 15));
try {
$client->setHeaders(Zend_Http_Client::CONTENT_TYPE, 'application/json; charset=utf-8')->setParameterGet('userId', urlencode($userId))->setParameterGet('serviceProviderEntityId', urlencode($spMetadata['EntityId']))->setParameterGet('identityProviderEntityId', urlencode($idpMetadata['EntityId']))->request('GET');
$body = $client->getLastResponse()->getBody();
$response = json_decode($body, true);
$status = $response['status'];
} catch (Exception $exception) {
$additionalInfo = new EngineBlock_Log_Message_AdditionalInfo($userId, $idpMetadata['EntityId'], $spMetadata['EntityId'], $exception->getTraceAsString());
EngineBlock_ApplicationSingleton::getLog()->error("Could not connect to License Manager" . $exception->getMessage(), $additionalInfo);
return EngineBlock_LicenseEngine_ValidationManager::LICENSE_UNKNOWN;
}
if ($status['returnUrl']) {
$currentResponse = EngineBlock_ApplicationSingleton::getInstance()->getHttpResponse();
$currentResponse->setRedirectUrl($status['returnUrl']);
$currentResponse->send();
exit;
} else {
if ($status['licenseStatus']) {
return $status['licenseStatus'];
} else {
return EngineBlock_LicenseEngine_ValidationManager::LICENSE_UNKNOWN;
}
}
}
示例4: testGetLastResponseWhenNotStoring
/**
* Test that getLastResponse returns null when not storing
*
*/
public function testGetLastResponseWhenNotStoring()
{
$this->client->setUri($this->baseuri . 'testHeaders.php');
$this->client->setConfig(array('storeresponse' => false));
$response = $this->client->request();
$this->assertEquals(null, $this->client->getLastResponse(), 'getLastResponse is expected to be null when not storing');
}
示例5: send
function send()
{
global $tikilib;
$entry = array();
$lastModif = 0;
$feed = $this->feed();
foreach ($feed->feed->entry as $item) {
if (empty($item->forwardlink->href)) {
continue;
}
$client = new Zend_Http_Client($item->forwardlink->href, array('timeout' => 60));
$info = $tikilib->get_page_info($item->page);
if ($info['lastModif'] > $lastModif) {
$lastModif = $info['lastModif'];
}
}
if (!empty($feed->feed->entry)) {
$client->setParameterGet(array('protocol' => 'forwardlink', 'contribution' => json_encode($feed)));
try {
$response = $client->request(Zend_Http_Client::POST);
$request = $client->getLastResponse();
return $response->getBody();
} catch (Exception $e) {
return "";
}
}
}
示例6: indexAction
public function indexAction()
{
$client = new Zend_Http_Client('https://ws.pagseguro.uol.com.br/v2/sessions/');
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterGet('email', 'ricardo@ricardomartins.info');
$client->setParameterGet('token', '9F79900A9B454CE6B18613D7224C0621');
$client->request();
var_dump($client->getLastResponse()->getBody());
}
示例7: testGetLastResponseWhenNotStoring
/**
* Test that getLastResponse returns null when not storing
*
*/
public function testGetLastResponseWhenNotStoring()
{
// Now, test we get a proper response after the request
$this->_client->setUri('http://example.com/foo/bar');
$this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
$this->_client->setConfig(array('storeresponse' => false));
$response = $this->_client->request();
$this->assertNull($this->_client->getLastResponse(), 'getLastResponse is expected to be null when not storing');
}
示例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: sendRequestSync
protected function sendRequestSync($url)
{
$client = new Zend_Http_Client($url);
Mage::helper('foomanjirafe')->debug($url);
$response = $client->request();
//check server response
if ($client->getLastResponse()->isError()) {
throw new Exception($response->getStatus() . ' ' . $response->getMessage());
}
return $response;
}
示例10: getStreamData
/**
* Get Stream Data.
*
*
* $data can also be stream (such as file) to which the data will be save.
*
* $client->setStream(); // will use temp file
* $response = $client->request('GET');
* // copy file
* copy($response->getStreamName(), "my/downloads/file");
* // use stream
* $fp = fopen("my/downloads/file2", "w");
* stream_copy_to_stream($response->getStream(), $fp);
* // Also can write to known file
* $client->setStream("my/downloads/myfile")->request('GET');
*
* @param resource $data
* @param string $enctype
* @return Default_Plugin_HttpBox
*/
function getStreamData($filename = null)
{
if (is_string($filename)) {
$this->client->setStream($filename)->request('GET');
} else {
$this->client->setStream();
// will use temp file
$this->client->request('GET');
}
// Запомним последний запрос в виде строки
$this->last_request = $this->client->getLastRequest();
// Запомним последний запрос в виде Zend_Http_Response
$this->last_response = $this->client->getLastResponse();
return $this;
}
示例11: provisionUser
/**
*
*
* @param $userId
* @param $attributes
* @param $spMetadata
* @param $idpMetadata
* @return void
*/
public function provisionUser($userId, $attributes, $spMetadata, $idpMetadata)
{
if (!$spMetadata['MustProvisionExternally']) {
return;
}
// https://os.XXX.surfconext.nl/provisioning-manager/provisioning/jit.shtml?
// provisionDomain=apps.surfnet.nl&provisionAdmin=admin%40apps.surfnet.nl&
// provisionPassword=xxxxx&provisionType=GOOGLE&provisionGroups=true
$client = new Zend_Http_Client($this->_url);
$client->setHeaders(Zend_Http_Client::CONTENT_TYPE, 'application/json; charset=utf-8')->setParameterGet('provisionType', $spMetadata['ExternalProvisionType'])->setParameterGet('provisionDomain', $spMetadata['ExternalProvisionDomain'])->setParameterGet('provisionAdmin', $spMetadata['ExternalProvisionAdmin'])->setParameterGet('provisionPassword', $spMetadata['ExternalProvisionPassword'])->setParameterGet('provisionGroups', $spMetadata['ExternalProvisionGroups'])->setRawData(json_encode($this->_getData($userId, $attributes)))->request('POST');
$additionalInfo = new EngineBlock_Log_Message_AdditionalInfo($userId, $idpMetadata['EntityId'], $spMetadata['EntityId'], null);
EngineBlock_ApplicationSingleton::getLog()->debug("PROVISIONING: Sent HTTP request to provision user using " . __CLASS__, $additionalInfo);
EngineBlock_ApplicationSingleton::getLog()->debug("PROVISIONING: URI: " . $client->getUri(true), $additionalInfo);
EngineBlock_ApplicationSingleton::getLog()->debug("PROVISIONING: REQUEST: " . $client->getLastRequest(), $additionalInfo);
EngineBlock_ApplicationSingleton::getLog()->debug("PROVISIONING: RESPONSE: " . $client->getLastResponse(), $additionalInfo);
}
示例12: getSessionId
/**
* Retorna o ID da sessao para ser usado nas chamadas JavaScript do Checkout Transparente
* ou FALSE no caso de erro
* @return bool|string
*/
public function getSessionId()
{
$client = new Zend_Http_Client($this->getWsUrl('sessions'));
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterGet('email', $this->getMerchantEmail());
$client->setParameterGet('token', $this->getToken());
$client->setConfig(array('timeout' => 30));
try {
$response = $client->request();
} catch (Exception $e) {
Mage::logException($e);
return false;
}
$response = $client->getLastResponse()->getBody();
libxml_use_internal_errors(true);
$xml = simplexml_load_string($response);
if (false === $xml) {
$this->writeLog('Falha na autenticação com API do PagSeguro. Verifique email e token cadastrados. Retorno pagseguro: ' . $response);
return false;
}
return (string) $xml->id;
}
示例13: _makeRequest
/**
* Make a request to Amazon S3
*
* @param string $method
* @param string $path
* @param array $headers
* @return Zend_Http_Response
*/
private function _makeRequest($method, $path, $headers = array())
{
$retry_count = 0;
if (!is_array($headers)) {
$headers = array($headers);
}
// Strip off the beginning s3:// (assuming this is the scheme used)
if (strpos($path, self::STREAM_ID) !== false) {
$path = substr($path, 5);
}
do {
$retry = false;
$headers['Date'] = gmdate(DATE_RFC1123, time());
self::addSignature($method, $path, $headers);
$client = new Zend_Http_Client(self::S3_ENDPOINT . '/' . $path);
$client->setHeaders($headers);
if ($method == 'PUT' && $this->_objectBuffer !== null) {
if (!isset($headers['Content-type'])) {
$headers['Content-type'] = self::getMimeType($path);
}
$client->setRawData($this->_objectBuffer, $headers['Content-type']);
}
$response = $client->request($method);
if (self::$logger instanceof Zend_Log) {
self::$logger->log($client->getLastRequest(), Zend_Log::INFO);
Zend_Debug::dump($client->getLastResponse());
//self::$logger->log($response, Zend_Log::INFO);
}
$response_code = $response->getStatus();
// Some 5xx errors are expected, so retry automatically
if ($response_code >= 500 && $response_code < 600 && $retry_count <= 5) {
$retry = true;
$retry_count++;
if (self::$logger instanceof Zend_Log) {
self::$logger->log($response_code . ' : retrying ' . $method . ' request (' . $retry_count . ')', Zend_Log::INFO);
}
sleep($retry_count / 4 * $retry_count);
} else {
if ($response_code == 307) {
echo "We need to redirect";
} else {
if ($response_code == 100) {
echo "OK to Continue";
}
}
}
} while ($retry);
return $response;
}
示例14: _call
protected function _call($endpoint, $params = null, $method = 'GET', $data = null, $silent = false, $global = false)
{
if ($params && is_array($params) && count($params) > 0) {
$args = array();
foreach ($params as $arg => $val) {
$args[] = urlencode($arg) . '=' . urlencode($val);
}
$endpoint .= '?' . implode('&', $args);
}
$url = $this->_getUrl($endpoint);
$method = strtoupper($method);
$client = new Zend_Http_Client($url);
$client->setMethod($method);
$client->setHeaders(array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
$client->setAuth($this->getUsername(), $this->getPassword());
if ($method == 'POST' || $method == "PUT") {
$client->setRawData(json_encode($data), 'application/json');
}
Mage::log(print_r(array('url' => $url, 'method' => $method, 'data' => json_encode($data)), true), null, 'zendesk.log');
try {
$response = $client->request();
} catch (Zend_Http_Client_Exception $ex) {
Mage::log('Call to ' . $url . ' resulted in: ' . $ex->getMessage(), Zend_Log::ERR, 'zendesk.log');
Mage::log('--Last Request: ' . $client->getLastRequest(), Zend_Log::ERR, 'zendesk.log');
Mage::log('--Last Response: ' . $client->getLastResponse(), Zend_Log::ERR, 'zendesk.log');
return array();
}
$body = json_decode($response->getBody(), true);
Mage::log(var_export($body, true), Zend_Log::DEBUG, 'zendesk.log');
if ($response->isError()) {
if (is_array($body) && isset($body['error'])) {
if (is_array($body['error']) && isset($body['error']['title'])) {
if (!$silent) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__($body['error']['title'], $response->getStatus()));
return;
} else {
return $body;
}
} else {
if (!$silent) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__($body['error'], $response->getStatus()));
return;
} else {
return $body;
}
}
} else {
if (!$silent) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__($body, $response->getStatus()));
return;
} else {
return $body;
}
}
}
return $body;
}
示例15: Abort
if (!isset($_GET['page']) or !$_GET['page']) {
Abort();
}
# Use the Zend_Uri class purely to validate whether the passed URI looks like a URI
require_once 'Zend/Uri.php';
$uri = Zend_Uri::factory($_GET['page']);
# Request the page to be parsed
/* @var $uri Zend_Uri_Http */
require_once 'Zend/Http/Client.php';
$user_agent = "Stoolball England microformats parser";
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$user_agent = $_SERVER['HTTP_USER_AGENT'] . "; {$user_agent}";
}
$client = new Zend_Http_Client($uri->__toString(), array('maxredirects' => 0, 'timeout' => 30, 'useragent' => $user_agent));
$client->request();
$response = $client->getLastResponse();
# Check we got a non-error status code
if ($response->getStatus() >= 400) {
Abort();
}
# Check we got some body content to parse
/* @var $response Zend_Http_Response */
$body = $response->getBody();
if (!$body) {
Abort();
}
# Load the XSLT file, which is from suda.co.uk
$xslFile = new DOMDocument();
$xslFile->load($_SERVER['DOCUMENT_ROOT'] . '/xhtml2vcal.xsl');
# Remove HTML the parser does not know how to deal with
$body = preg_replace('/<\\/?nav>/', "", $body);