本文整理汇总了PHP中Zend\Http\Client::resetParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::resetParameters方法的具体用法?PHP Client::resetParameters怎么用?PHP Client::resetParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Client
的用法示例。
在下文中一共展示了Client::resetParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getHttpClient
/**
* Get Http client
*
* @param string $url URL
* @param bool $resetParams Reset params
* @param string $method Method
* @param string $adapterName Adapter name
*
* @return Client
*/
protected function _getHttpClient($url, $resetParams = false, $method = Request::METHOD_GET, $adapterName = self::CONNECTION_CURL_ADAPTER)
{
$this->_httpClient = new Client($url);
$this->_httpClient->resetParameters($resetParams);
$this->_httpClient->setMethod($method)->setAdapter($adapterName);
return $this->_httpClient;
}
示例2: 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 Http\Client
*/
public static function getHttpClient()
{
if (!isset(static::$httpClient)) {
static::$httpClient = new Http\Client();
} else {
static::$httpClient->resetParameters();
}
return static::$httpClient;
}
示例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 HTTPClient();
} else {
self::$httpClient->setHeaders('Authorization', null);
self::$httpClient->resetParameters();
}
return self::$httpClient;
}
示例4: doSendInternalRequest
/**
* {@inheritdoc}
*/
protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
{
$this->client->resetParameters(true)->setOptions(array('httpversion' => $internalRequest->getProtocolVersion(), 'timeout' => $this->getConfiguration()->getTimeout(), 'maxredirects' => 0))->setUri($url = (string) $internalRequest->getUrl())->setMethod($internalRequest->getMethod())->setHeaders($this->prepareHeaders($internalRequest))->setRawBody($this->prepareBody($internalRequest));
try {
$response = $this->client->send();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUrl($url, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse($response->getStatusCode(), $response->getReasonPhrase(), $response->getVersion(), $response->getHeaders()->toArray(), BodyNormalizer::normalize(function () use($response) {
return $response instanceof Stream ? $response->getStream() : $response->getBody();
}, $internalRequest->getMethod()));
}
示例5: get
/**
* {@inheritDoc}
*/
public function get($uri, array $headers = [])
{
$this->client->resetParameters();
$this->client->setMethod('GET');
$this->client->setHeaders(new Headers());
$this->client->setUri($uri);
if (!empty($headers)) {
$this->injectHeaders($headers);
}
$response = $this->client->send();
return new Response($response->getStatusCode(), $response->getBody(), $this->prepareResponseHeaders($response->getHeaders()));
}
示例6: 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 HTTPClient();
} else {
$request = self::$httpClient->getRequest();
$headers = $request->getHeaders();
if ($headers->has('Authorization')) {
$auth = $headers->get('Authorization');
$headers->removeHeader($auth);
}
self::$httpClient->resetParameters();
}
return self::$httpClient;
}
示例7: call
/**
* Call MetaLib X-server
*
* @param string $operation X-Server operation
* @param array $params URL Parameters
*
* @return mixed simpleXMLElement
* @throws \Exception
*/
protected function call($operation, $params)
{
$this->debug("Call: {$this->host}: {$operation}: " . var_export($params, true));
// Declare UTF-8 encoding so that SimpleXML won't encode characters.
$xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><x_server_request/>');
$op = $xml->addChild($operation);
$this->paramsToXml($op, $params);
$this->client->resetParameters();
$this->client->setUri($this->host);
$this->client->setParameterPost(['xml' => $xml->asXML()]);
$result = $this->client->setMethod('POST')->send();
if (!$result->isSuccess()) {
throw new \Exception($result->getBody());
}
$xml = $result->getBody();
// Remove invalid XML fields (these were encountered in record Ppro853_304965
// from FIN05707)
$xml = preg_replace('/<controlfield tag=" ">.*?<\\/controlfield>/', '', $xml);
if ($xml = simplexml_load_string($xml)) {
$errors = $xml->xpath('//local_error | //global_error');
if (!empty($errors)) {
if ($errors[0]->error_code == 6026) {
throw new \Exception('Search timed out');
}
throw new \Exception($errors[0]->asXML());
}
$result = $xml;
}
return $result;
}
示例8: call
/**
* Submit REST Request
*
* @param string $method HTTP Method to use: GET or POST
* @param array $params An array of parameters for the request
* @param bool $process Should we convert the MARCXML?
*
* @return string|SimpleXMLElement The response from the XServer
*/
protected function call($method = 'GET', $params = null, $process = true)
{
if ($params) {
$query = ['version=' . $this->sruVersion];
foreach ($params as $function => $value) {
if (is_array($value)) {
foreach ($value as $additional) {
$additional = urlencode($additional);
$query[] = "{$function}={$additional}";
}
} else {
$value = urlencode($value);
$query[] = "{$function}={$value}";
}
}
$queryString = implode('&', $query);
}
$this->debug('Connect: ' . print_r($this->host . '?' . $queryString, true));
// Send Request
$this->client->resetParameters();
$this->client->setUri($this->host . '?' . $queryString);
$result = $this->client->setMethod($method)->send();
$this->checkForHttpError($result);
// Return processed or unprocessed response, as appropriate:
return $process ? $this->process($result->getBody()) : $result->getBody();
}
示例9: validate
/**
* @return CasResult
*/
public function validate()
{
try {
$uri = $this->createValidateUri();
} catch (Adapter\Exception\InvalidArgumentException $e) {
return new CasResult(CasResult::FAILURE, '', array($e->getMessage()));
}
$this->httpClient->resetParameters();
$this->httpClient->setUri($uri);
try {
$response = $this->httpClient->send();
} catch (Http\Exception\RuntimeException $e) {
return new CasResult(CasResult::FAILURE_UNCATEGORIZED, '', array($e->getMessage()));
}
if (!$response->isSuccess()) {
return new CasResult(CasResult::FAILURE_UNCATEGORIZED, '', array('HTTP response did not indicate success.'), $response->getBody());
}
$body = $response->getBody();
$explodedResponse = explode("\n", $body);
if (count($explodedResponse) < 2) {
return new CasResult(CasResult::FAILURE_UNCATEGORIZED, '', array('Got an invalid CAS 1.0 response.'), $body);
}
$status = $explodedResponse[0];
$identity = $explodedResponse[1];
if ($status !== 'yes') {
return new CasResult(CasResult::FAILURE_UNCATEGORIZED, '', array('Authentication failed.'), $body);
}
return new CasResult(CasResult::SUCCESS, $identity, array(), $body);
}
示例10: 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);
$this->client->setMethod('POST');
$res = $this->client->send();
$this->assertContains(serialize($params) . "\n" . serialize($params),
$res->getBody(), "returned body does not contain all GET and POST parameters (it should!)");
$this->client->resetParameters();
$this->client->setMethod('POST');
$res = $this->client->send();
$this->assertNotContains(serialize($params), $res->getBody(),
"returned body contains GET or POST parameters (it shouldn't!)");
$headerXFoo= $this->client->getHeader("X-Foo");
$this->assertTrue(empty($headerXFoo), "Header not preserved by reset");
}
示例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 Http\Client;
else:
self::$httpClient->resetParameters();
endif;
return self::$httpClient;
}
示例12: sendRequest
/**
* Sends a request.
*
* @param string $url The url.
* @param string $method The http method.
* @param array $headers The headers.
* @param array $content The content.
* @param array $files The files.
*
* @throws \Widop\HttpAdapter\HttpAdapterException If an error occured.
*
* @return \Widop\HttpAdapter\HttpResponse The response.
*/
private function sendRequest($url, $method, array $headers = array(), array $content = array(), array $files = array())
{
$this->client->resetParameters()->setOptions(array('maxredirects' => $this->getMaxRedirects()))->setMethod($method)->setUri($url)->setHeaders($headers)->setParameterPost($content);
foreach ($files as $key => $file) {
$this->client->setFileUpload($file, $key);
}
try {
$response = $this->client->send();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUrl($url, $this->getName(), $e->getMessage());
}
return $this->createResponse($response->getStatusCode(), $url, $response->getHeaders()->toArray(), $method === Request::METHOD_HEAD ? '' : $response->getBody());
}
示例13: sendRequest
/**
* Perform a single OAI-PMH request.
*
* @param string $verb OAI-PMH verb to execute.
* @param array $params GET parameters for ListRecords method.
*
* @return string
*/
protected function sendRequest($verb, $params)
{
// Set up the request:
$this->client->resetParameters();
$this->client->setUri($this->baseUrl);
// Load request parameters:
$query = $this->client->getRequest()->getQuery();
$query->set('verb', $verb);
foreach ($params as $key => $value) {
$query->set($key, $value);
}
// Perform request:
return $this->client->setMethod('GET')->send();
}
示例14: getRecord
/**
* Retrieve a specific record.
*
* @param string $id Record ID to retrieve
* @param ParamBag $params Parameters
*
* @throws \Exception
* @return array
*/
public function getRecord($id, ParamBag $params = null)
{
$query = "AN " . $id;
$params = $params ?: new ParamBag();
$params->set('prof', $this->prof);
$params->set('pwd', $this->pwd);
$params->set('query', $query);
$this->client->resetParameters();
$response = $this->call('GET', $params->getArrayCopy(), false);
$xml = simplexml_load_string($response);
$finalDocs = [];
foreach ($xml->SearchResults->records->rec as $doc) {
$finalDocs[] = simplexml_load_string($doc->asXML());
}
return ['docs' => $finalDocs, 'offset' => 0, 'total' => (int) $xml->Hits];
}
示例15: sendRequest
/**
* Make an OAI-PMH request. Die if there is an error; return a SimpleXML object
* on success.
*
* @param string $verb OAI-PMH verb to execute.
* @param array $params GET parameters for ListRecords method.
*
* @return object SimpleXML-formatted response.
*/
protected function sendRequest($verb, $params = [])
{
// Debug:
if ($this->verbose) {
$this->write("Sending request: verb = {$verb}, params = " . print_r($params, true));
}
// Set up retry loop:
while (true) {
// Set up the request:
$this->client->resetParameters();
$this->client->setUri($this->baseURL);
$this->client->setOptions(['timeout' => $this->timeout]);
// Set authentication, if necessary:
if ($this->httpUser && $this->httpPass) {
$this->client->setAuth($this->httpUser, $this->httpPass);
}
// Load request parameters:
$query = $this->client->getRequest()->getQuery();
$query->set('verb', $verb);
foreach ($params as $key => $value) {
$query->set($key, $value);
}
// Perform request and die on error:
$result = $this->client->setMethod('GET')->send();
if ($result->getStatusCode() == 503) {
$delayHeader = $result->getHeaders()->get('Retry-After');
$delay = is_object($delayHeader) ? $delayHeader->getDeltaSeconds() : 0;
if ($delay > 0) {
if ($this->verbose) {
$this->writeLine("Received 503 response; waiting {$delay} seconds...");
}
sleep($delay);
}
} else {
if (!$result->isSuccess()) {
throw new \Exception('HTTP Error');
} else {
// If we didn't get an error, we can leave the retry loop:
break;
}
}
}
// If we got this far, there was no error -- send back response.
return $this->processResponse($result->getBody());
}