本文整理匯總了PHP中Zend\Http\Client::setUri方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::setUri方法的具體用法?PHP Client::setUri怎麽用?PHP Client::setUri使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Http\Client
的用法示例。
在下文中一共展示了Client::setUri方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getResults
/**
* @return array
*/
public function getResults($offset, $itemCountPerPage)
{
$query = $this->createSearchQuery($offset, $itemCountPerPage);
$adapter = new Http\Client\Adapter\Curl();
$adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
$client = new Http\Client();
$client->setAdapter($adapter);
$client->setMethod('GET');
$client->setUri($this->getOptions()->getSearchEndpoint() . $query);
$response = $client->send();
if (!$response->isSuccess()) {
throw new Exception\RuntimeException("Invalid response received from CloudSearch.\n" . $response->getContent());
}
$results = Json::decode($response->getContent(), Json::TYPE_ARRAY);
$this->count = $results['hits']['found'];
if (0 == $this->count) {
return array();
}
if ($this->getOptions()->getReturnIdResults()) {
$results = $this->extractResultsToIdArray($results);
}
foreach ($this->getConverters() as $converter) {
$results = $converter->convert($results);
}
return $results;
}
示例2: setPostRut
function setPostRut($ruts)
{
foreach ($ruts as $rut) {
$busqueda[] = explode('-', $rut[0]);
}
echo '<pre>';
print_r($busqueda);
echo '</pre>';
$client = new Client('http://reca.poderjudicial.cl/', array('maxredirects' => 100, 'timeout' => 600, 'keepalive' => true));
$headers = $client->getRequest()->getHeaders();
$cookies = new Zend\Http\Cookies($headers);
$client->setMethod('GET');
$response = $client->send();
$client->setUri('http://reca.poderjudicial.cl/RECAWEB/AtPublicoViewAccion.do?tipoMenuATP=1');
$cookies->addCookiesFromResponse($response, $client->getUri());
$response = $client->send();
$client->setUri("http://reca.poderjudicial.cl/RECAWEB/AtPublicoDAction.do");
foreach ($busqueda as $rut) {
$parametros = array('actionViewBusqueda' => '2', 'FLG_Busqueda' => '2', 'FLG_User_Valid' => '0', 'TIP_Lengueta' => 'tdDos', 'COD_Competencia' => 'C', 'tribunal_aux' => '-1', 'username_aux' => '', 'password_aux' => '', 'aux_codlibro' => '', 'aux_rolinterno' => '', 'aux_eracausa' => '', 'aux_codcorte' => '', 'RUT_Cod_Competencia' => 'C', 'RUT_Rut' => $rut[0], 'RUT_Rut_Db' => $rut[1], 'RIT_Cod_Competencia' => '0', 'RIT_Tip_Causa' => '0', 'RIT_Rol_Interno' => '', 'RIT_Era_Causa' => '', 'corte_Cod_Tribunal' => '-1', 'corte_Cod_Libro' => '0', 'corte_Rol_Interno' => '', 'corte_Era_Causa' => '', 'OPC_Cod_Corte' => '-1', 'OPC_Cod_Tribunal' => '-1', 'username' => '', 'password' => '');
$client->setParameterPost($parametros);
echo '<pre>';
print_r($parametros);
echo '</pre>';
$response = $client->setMethod('POST')->send();
$data = $response->getContent();
echo '<pre>';
print_r($response->getContent());
echo '</pre>';
die;
$rut = $rut[0] . '-' . $rut[1];
$dom = new Query($data);
$resultados = $dom->execute('#divRecursos tr');
$rols = $this->busquedaRut($resultados, $rut);
}
}
示例3: fetchLinks
/**
* Fetch Links
*
* Fetches a set of links corresponding to an OpenURL
*
* @param string $openURL openURL (url-encoded)
*
* @return string raw XML returned by resolver
*/
public function fetchLinks($openURL)
{
// Make the call to SFX and load results
$url = $this->baseUrl . '?sfx.response_type=multi_obj_detailed_xml&svc.fulltext=yes&' . $openURL;
$feed = $this->httpClient->setUri($url)->send()->getBody();
return $feed;
}
示例4: setRequestHandler
/**
* Sets request handler
*
* @param \Zend\Http\Client $handler
* @return RemoteCompiler
*/
public function setRequestHandler($handler)
{
$this->requestHandler = $handler;
$this->requestHandler->setUri($this->url)->setMethod($this->method);
$this->requestHandler->getUri()->setPort($this->port);
return $this;
}
示例5: updateAddressFormats
/**
* @param ProgressAdapter|null $progressAdapter
*/
public function updateAddressFormats(ProgressAdapter $progressAdapter = null)
{
$localeDataUri = $this->options->getLocaleDataUri();
$dataPath = $this->options->getDataPath();
$locales = json_decode($this->httpClient->setUri($localeDataUri)->send()->getContent());
foreach (scandir($dataPath) as $file) {
if (fnmatch('*.json', $file)) {
unlink($dataPath . '/' . $file);
}
}
$countryCodes = isset($locales->countries) ? explode('~', $locales->countries) : [];
$countryCodes[] = 'ZZ';
if ($progressAdapter !== null) {
$progressBar = new ProgressBar($progressAdapter, 0, count($countryCodes));
}
foreach ($countryCodes as $countryCode) {
file_put_contents($dataPath . '/' . $countryCode . '.json', $this->httpClient->setUri($localeDataUri . '/' . $countryCode)->send()->getContent());
if (isset($progressBar)) {
$progressBar->next();
}
}
if (isset($progressBar)) {
$progressBar->finish();
}
// We clearly don't want the "ZZ" in the array!
array_pop($countryCodes);
$writer = new PhpArrayWriter();
$writer->setUseBracketArraySyntax(true);
$writer->toFile($this->options->getCountryCodesPath(), $countryCodes, false);
}
示例6: fetchLinks
/**
* Fetch Links
*
* Fetches a set of links corresponding to an OpenURL
*
* @param string $openURL openURL (url-encoded)
*
* @return string raw XML returned by resolver
*/
public function fetchLinks($openURL)
{
// Make the call to SerialsSolutions and load results
$url = $this->baseUrl . (substr($this->baseUrl, -1) == '/' ? '' : '/') . 'openurlxml?version=1.0&' . $openURL;
$feed = $this->httpClient->setUri($url)->send()->getBody();
return $feed;
}
示例7: __construct
public function __construct($config)
{
if (!isset($config['yql_base_url'])) {
throw new \InvalidArgumentException('Missing yql_base_url in config');
}
$this->client = new Client();
$this->client->setUri($config['yql_base_url']);
$this->client->setOptions(array('maxredirects' => 0, 'timeout' => 10));
}
示例8: getContent
/**
* {@inheritDoc}
*/
public function getContent($url)
{
try {
$response = $this->client->setUri($url)->send();
$content = $response->isSuccess() ? $response->getBody() : null;
} catch (\Exception $e) {
$content = null;
}
return $content;
}
示例9: request
/**
* Call ja.is service and convert address to lat and lng
*
* @param string $address
* @return object
*/
public function request($address)
{
$response = $this->client->setUri("http://ja.is/kort/leit")->setMethod('GET')->setParameterGet(['q' => $address])->send();
if ($response->getStatusCode() == 200) {
$json = json_decode($response->getBody());
return isset($json->items[0]->coordinates) ? (object) ['lat' => (double) $json->items[0]->coordinates->lat, 'lng' => (double) $json->items[0]->coordinates->lon] : (object) ['lat' => null, 'lng' => null];
} else {
return (object) ['lat' => null, 'lng' => null];
}
}
示例10: 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()));
}
示例11: fetch
/**
* Fetch an image from either a URL or the cache (as appropriate).
*
* @param string $url URL to fetch
*
* @return Response
*/
public function fetch($url)
{
$file = $this->getCacheFile($url);
$cacheAllowed = $this->onWhitelist($url);
if (!$cacheAllowed || !($response = $this->fetchCache($file))) {
$response = $this->client->setUri($url)->send();
if ($cacheAllowed) {
$this->setCache($file, $response);
}
}
return $response;
}
示例12: query
public static function query($api, $command, $options = null)
{
// Validate configuration
if (!self::getApiKey()) {
throw new \Exception('Echonest has not been configured');
}
$http = new Client();
$http->setUri(self::$source . $api . '/' . $command);
$http->setOptions(array('sslverifypeer' => false));
$http->setMethod('GET');
$format = 'json';
if (is_array($options)) {
$http->setUri(self::$source . $api . '/' . $command);
$options['api_key'] = self::getApiKey();
if (!isset($options['format'])) {
$options['format'] = $format;
} else {
$format = $options['format'];
}
// Build query manually as $http->setParameterGet builds arrays properly:
// echonest api is not standard :/
// We need ?bucket=audio_summary&bucket=artist_discovery NOT ?bucket[0]=audio_summary&bucket[1]=artist_discovery
//strip array indexes
$http_query = preg_replace('/%5B[0-9]+%5D/simU', '', http_build_query($options));
$http->setUri(self::$source . $api . '/' . $command . '?' . $http_query);
} else {
#options as a query string
if (!$options) {
throw new \Exception("The options must be an array or a non empty string");
}
if (!strpos($options, 'api_key')) {
$options .= '&api_key=' . self::getApiKey();
}
#find format in query string
preg_match('/format=([^&]+)&/', $options, $matches);
if (is_array($matches)) {
$format = $matches[1] ? $matches[1] : 'json';
}
$http->setUri(self::$source . $api . '/' . $command . '?' . $options);
}
$response = $http->send();
#output response according to format
if ($format == 'xml') {
return simplexml_load_string($response->getBody());
} else {
return Json::decode($response->getBody());
}
}
示例13: pesquisaCep
public function pesquisaCep($strCEP)
{
$httpClient = new Client();
$httpClient->setUri('http://webservice.kinghost.net/web_cep.php')->setParameterGet(array('auth' => $this->auth, 'formato' => 'json', 'cep' => $strCEP));
$response = (object) json_decode($httpClient->send()->getBody(), true);
return array('uf' => $response->uf, 'cidade' => $response->cidade, 'bairro' => $response->bairro, 'logradouro' => $response->logradouro, 'status' => $response->resultado ? true : false, 'message' => !$response->resultado ? 'CEP não encontrado' : '');
}
示例14: send
/**
* @param MessageInterface|Message $message
* @return mixed|void
* @throws RuntimeException
*/
public function send(MessageInterface $message)
{
$config = $this->getSenderOptions();
$serviceURL = "http://letsads.com/api";
$body = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><request></request>');
$auth = $body->addChild('auth');
$auth->addChild('login', $config->getUsername());
$auth->addChild('password', $config->getPassword());
$messageXML = $body->addChild('message');
$messageXML->addChild('from', $config->getSender());
$messageXML->addChild('text', $message->getMessage());
$messageXML->addChild('recipient', $message->getRecipient());
$client = new Client();
$client->setMethod(Request::METHOD_POST);
$client->setUri($serviceURL);
$client->setRawBody($body->asXML());
$client->setOptions(['sslverifypeer' => false, 'sslallowselfsigned' => true]);
try {
$response = $client->send();
} catch (Client\Exception\RuntimeException $e) {
throw new RuntimeException("Failed to send sms", null, $e);
}
try {
$responseXML = new \SimpleXMLElement($response->getBody());
} catch (\Exception $e) {
throw new RuntimeException("Cannot parse response", null, $e);
}
if ($responseXML->name === 'error') {
throw new RuntimeException("LetsAds return error (" . $responseXML->description . ')');
}
}
示例15: 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);
}