本文整理汇总了PHP中Zend\Http\Client::setMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setMethod方法的具体用法?PHP Client::setMethod怎么用?PHP Client::setMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Client
的用法示例。
在下文中一共展示了Client::setMethod方法的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: indexAction
public function indexAction()
{
$client = new HttpClient();
$client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
$method = $this->params()->fromQuery('method', 'get');
$client->setUri('http://api-rest/san-restful');
switch ($method) {
case 'get':
$id = $this->params()->fromQuery('id');
$client->setMethod('GET');
$client->setParameterGET(array('id' => $id));
break;
case 'get-list':
$client->setMethod('GET');
break;
case 'create':
$client->setMethod('POST');
$client->setParameterPOST(array('name' => 'samsonasik'));
break;
case 'update':
$data = array('name' => 'ikhsan');
$adapter = $client->getAdapter();
$adapter->connect('localhost', 80);
$uri = $client->getUri() . '?id=1';
// send with PUT Method, with $data parameter
$adapter->write('PUT', new \Zend\Uri\Uri($uri), 1.1, array(), http_build_query($data));
$responsecurl = $adapter->read();
list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('content-type', 'text/html; charset=utf-8');
$response->setContent($content);
return $response;
case 'delete':
$adapter = $client->getAdapter();
$adapter->connect('localhost', 80);
$uri = $client->getUri() . '?id=1';
//send parameter id = 1
// send with DELETE Method
$adapter->write('DELETE', new \Zend\Uri\Uri($uri), 1.1, array());
$responsecurl = $adapter->read();
list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('content-type', 'text/html; charset=utf-8');
$response->setContent($content);
return $response;
}
//if get/get-list/create
$response = $client->send();
if (!$response->isSuccess()) {
// report failure
$message = $response->getStatusCode() . ': ' . $response->getReasonPhrase();
$response = $this->getResponse();
$response->setContent($message);
return $response;
}
$body = $response->getBody();
$response = $this->getResponse();
$response->setContent($body);
return $response;
}
示例4: _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;
}
示例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: send
/**
* {@inheritdoc}
*/
public function send($url, $payload)
{
try {
$response = $this->client->setMethod('POST')->setUri($url)->setRawBody($payload)->setHeaders($this->getHeaders(true))->send();
} catch (RuntimeException $e) {
throw TcpException::transportError($e);
}
if ($response->getStatusCode() !== 200) {
throw HttpException::httpError($response->getReasonPhrase(), $response->getStatusCode());
}
return $response->getBody();
}
示例7: __construct
/**
* Constructor
*
* @param string $base Base URL for Pazpar2
* @param \Zend\Http\Client $client An HTTP client object
* @param bool $autoInit Should we auto-initialize the Pazpar2
* connection?
*/
public function __construct($base, \Zend\Http\Client $client, $autoInit = false)
{
$this->base = $base;
if (empty($this->base)) {
throw new \Exception('Missing Pazpar2 base URL.');
}
$this->client = $client;
$this->client->setMethod(Request::METHOD_GET);
// always use GET
if ($autoInit) {
$this->init();
}
}
示例8: indexAction
/**
* Redirects the user to a YUML graph drawn with the provided `dsl_text`
*
* @return \Zend\Http\Response
*
* @throws \UnexpectedValueException if the YUML service answered incorrectly
*/
public function indexAction()
{
/* @var $request \Zend\Http\Request */
$request = $this->getRequest();
$this->httpClient->setMethod(Request::METHOD_POST);
$this->httpClient->setParameterPost(array('dsl_text' => $request->getPost('dsl_text')));
$response = $this->httpClient->send();
if (!$response->isSuccess()) {
throw new \UnexpectedValueException('HTTP Request failed');
}
/* @var $redirect \Zend\Mvc\Controller\Plugin\Redirect */
$redirect = $this->plugin('redirect');
return $redirect->toUrl('http://yuml.me/' . $response->getBody());
}
示例9: create
/**
* Add a new subscription
*
* @return JsonModel
*/
public function create($data)
{
$username = $this->params()->fromRoute('username');
$usersTable = $this->getTable('UsersTable');
$user = $usersTable->getByUsername($username);
$userFeedsTable = $this->getTable('UserFeedsTable');
$rssLinkXpath = '//link[@type="application/rss+xml"]';
$faviconXpath = '//link[@rel="shortcut icon"]';
$client = new Client($data['url']);
$client->setEncType(Client::ENC_URLENCODED);
$client->setMethod(\Zend\Http\Request::METHOD_GET);
$response = $client->send();
if ($response->isSuccess()) {
$html = $response->getBody();
$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
$dom = new Query($html);
$rssUrl = $dom->execute($rssLinkXpath);
if (!count($rssUrl)) {
throw new Exception('Rss url not found in the url provided', 404);
}
$rssUrl = $rssUrl->current()->getAttribute('href');
$faviconUrl = $dom->execute($faviconXpath);
if (count($faviconUrl)) {
$faviconUrl = $faviconUrl->current()->getAttribute('href');
} else {
$faviconUrl = null;
}
} else {
throw new Exception("Website not found", 404);
}
$rss = Reader::import($rssUrl);
return new JsonModel(array('result' => $userFeedsTable->create($user->id, $rssUrl, $rss->getTitle(), $faviconUrl)));
}
示例10: fetch
/**
* @return Workspace
*/
public function fetch()
{
$events = $this->getEventManager();
$event = new DeployEvent(null, $this);
$events->trigger(DeployEvent::EVENT_FETCH_PRE, $event);
// Check for filename, if any
$response = $this->client->setMethod(Request::METHOD_HEAD)->send();
$destination = $this->getStreamPath($response->getHeaders());
// retrieve file
$this->client->setMethod(Request::METHOD_GET)->setStream($destination->getPathname())->send();
// create build file
$workspace = new Workspace($destination->getPathname());
$event->setWorkspace($workspace);
$events->trigger(DeployEvent::EVENT_FETCH_POST, $event);
return $workspace;
}
示例11: PlanJSONManager
function PlanJSONManager($action, $url, $requestjson, $uid)
{
$request = new Request();
$request->getHeaders()->addHeaders(array('Content-Type' => 'application/json; charset=UTF-8'));
//$url="";
try {
$request->setUri($url);
$request->setMethod($action);
$client = new Client();
if ($action == 'PUT' || $action == 'POST') {
$client->setUri($url);
$client->setMethod($action);
$client->setRawBody($requestjson);
$client->setEncType('application/json');
$response = $client->send();
return $response;
} else {
$response = $client->dispatch($request);
//var_dump(json_decode($response->getBody(),true));
return $response;
}
} catch (\Exception $e) {
$e->getTrace();
}
return null;
}
示例12: getLatLng
public static function getLatLng($address)
{
$latLng = [];
try {
$url = sprintf('http://maps.google.com/maps/api/geocode/json?address=%s&sensor=false', $address);
$client = new Client($url);
$client->setAdapter(new Curl());
$client->setMethod('GET');
$client->setOptions(['curloptions' => [CURLOPT_HEADER => false]]);
$response = $client->send();
$body = $response->getBody();
$result = Json\Json::decode($body, 1);
$latLng = ['lat' => $result['results'][0]['geometry']['location']['lat'], 'lng' => $result['results'][0]['geometry']['location']['lng']];
$isException = false;
} catch (\Zend\Http\Exception\RuntimeException $e) {
$isException = true;
} catch (\Zend\Http\Client\Adapter\Exception\RuntimeException $e) {
$isException = true;
} catch (Json\Exception\RuntimeException $e) {
$isException = true;
} catch (Json\Exception\RecursionException $e2) {
$isException = true;
} catch (Json\Exception\InvalidArgumentException $e3) {
$isException = true;
} catch (Json\Exception\BadMethodCallException $e4) {
$isException = true;
}
if ($isException === true) {
//código em caso de problemas no decode
}
return $latLng;
}
示例13: 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 . ')');
}
}
示例14: addressFromCep
/**
* Efetua consulta de cep.
*
* @param type $cep
* @return type
* @throws Exception
*/
public function addressFromCep($cep)
{
if (!file_exists(self::CONFIG_FILE)) {
throw new Exception("Arquivo de configurações do cliente BYJG não existe");
}
$config = (include self::CONFIG_FILE);
$result = array('found' => false);
try {
// Requisicao ao BYJG que prove base de dados gratuita para CEP
$byJg = new Client(self::HOST);
$byJg->setMethod(Request::METHOD_POST);
$byJg->setParameterPost(array('httpmethod' => 'obterlogradouroauth', 'cep' => $cep, 'usuario' => $config['username'], 'senha' => $config['password']));
$response = $byJg->send();
if ($response->isOk()) {
// captura resultado e organiza dados
$body = preg_replace("/^OK\\|/", "", $response->getBody());
// Separa as partes do CEP
$parts = explode(", ", $body);
if (count($parts) <= 1) {
throw new Exception("Resposta ByJG não pode suprir CEP como esperado");
}
$result['found'] = true;
list($result['logradouro'], $result['bairro'], $result['cidade'], $result['estado'], $result['codIbge']) = $parts;
}
} catch (Exception $e) {
Firephp::getInstance()->err($e->__toString());
}
return $result;
}
示例15: readStream
/**
* Get a read-stream for a file
*
* @param $path
* @return array|bool
*/
public function readStream($path)
{
$headers = ['User-Agent' => 'testing/1.0', 'Accept' => 'application/json', 'X-Foo' => ['Bar', 'Baz'], 'custom' => 'cust'];
$stream = \GuzzleHttp\Stream\Stream::factory('contents...');
$client = new \GuzzleHttp\Client(['headers' => $headers]);
$resource = fopen('a.gif', 'r');
$request = $client->put($this->api_url . 'upload', ['body' => $resource]);
prn($client, $request);
echo $request->getBody();
exit;
$location = $this->applyPathPrefix($path);
$this->client->setMethod('PUT');
$this->client->setUri($this->api_url . 'upload');
$this->client->setParameterPost(array_merge($this->auth_param, ['location' => $location]));
// $this->client
// //->setHeaders(['path: /usr/local....'])
// ->setFileUpload('todo.txt','r')
// ->setRawData(fopen('todo.txt','r'));
$fp = fopen('todo.txt', "r");
$curl = $this->client->getAdapter();
$curl->setCurlOption(CURLOPT_PUT, 1)->setCurlOption(CURLOPT_RETURNTRANSFER, 1)->setCurlOption(CURLOPT_INFILE, $fp)->setCurlOption(CURLOPT_INFILESIZE, filesize('todo.txt'));
// prn($curl->setOutputStream($fp));
$response = $this->client->send();
prn($response->getContent(), json_decode($response->getContent()));
exit;
}