本文整理汇总了PHP中Zend_Http_Client::resetParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client::resetParameters方法的具体用法?PHP Zend_Http_Client::resetParameters怎么用?PHP Zend_Http_Client::resetParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Client
的用法示例。
在下文中一共展示了Zend_Http_Client::resetParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare
/**
* HTTP client preparation procedures - should be called before every API
* call.
*
* Will clean up the HTTP client parameters, set the request method to POST
* and add the always-required authentication information
*
* @param string $method The API method we are about to use
* @return void
*/
protected function prepare($method)
{
// Reset parameters
$this->httpClient->resetParameters();
// Add authentication data
$this->httpClient->setMethod('POST');
$this->httpClient->setParameterPost(array('USER' => $this->authInfo->getUser(), 'PWD' => $this->authInfo->getPassword(), 'SIGNATURE' => $this->authInfo->getSignature(), 'VERSION' => '2.3', 'METHOD' => $method));
}
示例2: _getClient
/**
* @return Zend_Http_Client
*/
protected function _getClient()
{
if (is_null($this->_httpClient)) {
if (!$this->_apiUri) {
Mage::throwException('Please specify API uri.');
}
$this->_httpClient = new Zend_Http_Client($this->_apiUri);
}
return $this->_httpClient->resetParameters(true);
}
示例3: getHttpClient
/**
* Return the singleton instance of the HTTP Client. Note that
* the instance is reset and cleared of previous parameters and
* Authorization header values.
*
* @return Zend_Http_Client
*/
public static function getHttpClient()
{
if (!isset(self::$httpClient)) {
self::$httpClient = new Zend_Http_Client();
} else {
self::$httpClient->setHeaders('Authorization', null);
self::$httpClient->resetParameters();
}
return self::$httpClient;
}
示例4: 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()));
}
示例5: 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();
}
示例6: postComment
/**
* Post a comment.
*
* @param string $code
* @param string $message
* @param array $options
* @param string $format
*/
public function postComment($code, $message, $options = array(), $format = self::FORMAT_XML)
{
$defaults = array('name' => '', 'email' => '', 'tweet' => 0);
$options = array_merge($defaults, $options);
if (!strlen($options['name']) && !strlen($options['email'])) {
if (null == $this->_username && null == $this->_password) {
throw new HausDesign_Service_Mobypicture_Exception('name and email or username and password should by defined');
}
}
$this->_localHttpClient->resetParameters();
$this->_localHttpClient->setUri(self::MOBYPICTURE_API);
$this->_localHttpClient->setParameterGet('action', 'postComment');
if (!strlen($options['name']) && !strlen($options['email'])) {
$this->_localHttpClient->setParameterGet('u', $this->_username);
$this->_localHttpClient->setParameterGet('p', $this->_password);
}
$this->_localHttpClient->setParameterGet('k', $this->_apiKey);
$this->_localHttpClient->setParameterGet('tinyurl_code ', $code);
$this->_localHttpClient->setParameterGet('message', $code);
$this->_localHttpClient->setParameterGet('format', $format);
foreach ($options as $option => $value) {
$this->_localHttpClient->setParameterGet($option, $value);
}
return $this->_parseContent($this->_localHttpClient->request('GET')->getBody(), $format);
}
示例7: getFeed
/**
* Retreive feed object
*
* @param string $uri
* @return Zend_Feed
*/
public function getFeed($uri)
{
$feed = new Zend_Feed();
$this->_httpClient->resetParameters();
$feed->setHttpClient($this->_httpClient);
return $feed->import($uri);
}
示例8: testResetParameters
/**
* Make sure we can reset the parameters between consecutive requests
*
*/
public function testResetParameters()
{
$params = array(
'quest' => 'To seek the holy grail',
'YourMother' => 'Was a hamster',
'specialChars' => '<>$+ &?=[]^%',
'array' => array('firstItem', 'secondItem', '3rdItem')
);
$headers = array("X-Foo" => "bar");
$this->client->setParameterPost($params);
$this->client->setParameterGet($params);
$this->client->setHeaders($headers);
$res = $this->client->request('POST');
$this->assertContains(serialize($params) . "\n" . serialize($params),
$res->getBody(), "returned body does not contain all GET and POST parameters (it should!)");
$this->client->resetParameters();
$res = $this->client->request('POST');
$this->assertNotContains(serialize($params), $res->getBody(),
"returned body contains GET or POST parameters (it shouldn't!)");
$this->assertContains($headers["X-Foo"], $this->client->getHeader("X-Foo"), "Header not preserved by reset");
$this->client->resetParameters(true);
$this->assertNull($this->client->getHeader("X-Foo"), "Header preserved by reset(true)");
}
示例9: _request
/**
* Makes request and checks the result according uri
*
* @param string $uri
* @return stdClass
* @throws \Exception when the result was unsuccessful
* @throws \UnexpectedValueException JSON parsing error
*/
protected function _request($uri)
{
// request object
$request = $this->_httpClient->resetParameters(true)->setUri($uri);
// let's send request and check what we have
try {
$response = $request->request();
} catch (\Zend_Http_Client_Exception $e) {
throw new \Exception('Client request was unsuccessful', $e->getCode(), $e);
}
if (!$response->isSuccessful()) {
throw new \Exception("Request failed({$response->getStatus()}): {$response->getMessage()} at " . $request->getLastRequest());
}
// the response has JSON format, we should decode it
try {
$decoded = \Zend_Json::decode($response->getBody(), \Zend_Json::TYPE_OBJECT);
} catch (\Zend_Json_Exception $e) {
throw new \UnexpectedValueException('Response is not JSON: ' . $response->getBody());
}
// do we have something interesting?
if (isset($decoded->error)) {
if (!isset($decoded->error->error_code)) {
$this->_errorMessage = $decoded->error;
} else {
throw new \Exception("Response contains error({$decoded->error->error_code}): " . $decoded->error->error_msg);
}
}
return $decoded;
}
示例10: _httpRequest
/**
* Performs HTTP request to given $url using given HTTP $method.
* Send additinal query specified by variable/value array,
* On success returns HTTP response without headers, false on failure.
*
* @param string $url OpenID server url
* @param string $method HTTP request method 'GET' or 'POST'
* @param array $params additional qwery parameters to be passed with
* @param int &$staus HTTP status code
* request
* @return mixed
*/
protected function _httpRequest($url, $method = 'GET', array $params = array(), &$status = null)
{
$client = $this->_httpClient;
if ($client === null) {
$client = new Zend_Http_Client($url, array('maxredirects' => 4, 'timeout' => 15, 'useragent' => 'Zend_OpenId'));
} else {
$client->setUri($url);
}
$client->resetParameters();
if ($method == 'POST') {
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterPost($params);
} else {
$client->setMethod(Zend_Http_Client::GET);
$client->setParameterGet($params);
}
try {
$response = $client->request();
} catch (Exception $e) {
$this->_setError('HTTP Request failed: ' . $e->getMessage());
return false;
}
$status = $response->getStatus();
$body = $response->getBody();
if ($status == 200 || $status == 400 && !empty($body)) {
return $body;
} else {
$this->_setError('Bad HTTP response');
return false;
}
}
示例11: getHttpClient
/**
* Return the singleton instance of the HTTP Client. Note that
* the instance is reset and cleared of previous parameters GET/POST.
* Headers are NOT reset but handled by this component if applicable.
*
* @return Zend_Http_Client
*/
public static function getHttpClient()
{
if (!isset(self::$httpClient)):
self::$httpClient = new Zend_Http_Client;
else:
self::$httpClient->resetParameters();
endif;
return self::$httpClient;
}
示例12: resetParameters
/**
* Clear all GET and POST parameters
*
* Should be used to reset the request parameters if the client is
* used for several concurrent requests.
*
* clearAll parameter controls if we clean just parameters or also
* headers and last_*
*
* @param bool $clearAll Should all data be cleared?
* @return Default_Plugin_HttpBox
*/
function resetParameters($clearAll = false)
{
$this->last_url = null;
$this->last_request = null;
$this->last_response = null;
$this->last_cookies = null;
$this->last_config = null;
$this->client->resetParameters($clearAll);
return $this;
}
示例13: delete
/**
* DELETE entry with client object
*
* @param mixed $data The Zend_Gdata_App_Entry or URL to delete
* @return void
* @throws Zend_Gdata_App_Exception
* @throws Zend_Gdata_App_HttpException
* @throws Zend_Gdata_App_InvalidArgumentException
*/
public function delete($data, $remainingRedirects = null)
{
require_once 'Zend/Http/Client/Exception.php';
if ($remainingRedirects === null) {
$remainingRedirects = self::getMaxRedirects();
}
if (is_string($data)) {
$uri = $data;
} elseif ($data instanceof Zend_Gdata_App_Entry) {
$editLink = $data->getEditLink();
if ($editLink != null) {
$uri = $editLink->getHref();
}
} else {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException('You must specify the data to post as either a string or a child of Zend_Gdata_App_Entry');
}
if ($uri === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
}
$this->_httpClient->resetParameters();
$this->_httpClient->setHeaders('x-http-method-override', null);
$this->_httpClient->setUri($uri);
$this->_httpClient->setConfig(array('maxredirects' => 0));
try {
if (Zend_Gdata_App::getHttpMethodOverride()) {
$this->_httpClient->setHeaders(array('X-HTTP-Method-Override: DELETE'));
$this->_httpClient->setRawData('');
$response = $this->_httpClient->request('POST');
} else {
$response = $this->_httpClient->request('DELETE');
}
} catch (Zend_Http_Client_Exception $e) {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
}
if ($response->isRedirect()) {
if ($remainingRedirects > 0) {
$newUri = $response->getHeader('Location');
$response = $this->delete($newUri, $remainingRedirects - 1);
} else {
require_once 'Zend/Gdata/App/HttpException.php';
throw new Zend_Gdata_App_HttpException('No more redirects allowed', null, $response);
}
}
if (!$response->isSuccessful()) {
require_once 'Zend/Gdata/App/HttpException.php';
$exception = new Zend_Gdata_App_HttpException('Expected response code 200, got ' . $response->getStatus());
$exception->setResponse($response);
throw $exception;
}
return $response;
}
示例14: _getZendHttpClient
/**
* private getter for the Zend_Http_Client
* if not set yet it will be instantiated
*
* @return Zend_Http_Client
*/
protected function _getZendHttpClient()
{
if (is_null($this->_httpClient)) {
// @todo implement SSL check here
$this->_httpClient = new Zend_Http_Client($this->_getRequestUrl());
} else {
$this->_httpClient->resetParameters(true);
$this->_httpClient->setUri($this->_getRequestUrl());
}
return $this->_httpClient;
}
示例15: login
/**
* Login to the API, set the auth header.
* @throws Zend_Http_Client_Exception
* @throws Exception
*/
protected function login()
{
$this->client->setUri($this->config['uri'] . $this->config['endpoints']['auth']);
$this->client->setParameterPost($this->config['credentials']);
$response = $this->client->request('POST');
if ($response->getStatus() > 299) {
throw new Exception('Unable to login, user credentials in config incorrect');
}
$jsonResponse = json_decode($response->getBody(), true);
$this->client->resetParameters();
$this->client->setHeaders('Authorization', 'Bearer ' . $jsonResponse['access_token']);
}