当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::setMethod方法代码示例

本文整理汇总了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;
 }
开发者ID:outeredge,项目名称:edge-zf2,代码行数:29,代码来源:CloudSearchSearcher.php

示例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);
     }
 }
开发者ID:jpablocasanueva,项目名称:pjud_v1,代码行数:35,代码来源:busquedaRut.php

示例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;
 }
开发者ID:AlboVieira,项目名称:api-rest,代码行数:60,代码来源:SampleRestClient.php

示例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;
 }
开发者ID:VaD1ke,项目名称:redmine_telegram_notifier,代码行数:17,代码来源:Provider.php

示例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()));
 }
开发者ID:DenLilleMand,项目名称:christianssite,代码行数:15,代码来源:ZendHttpClientDecorator.php

示例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();
 }
开发者ID:Banjerr,项目名称:infusionPress_Forms,代码行数:15,代码来源:ZendFrameworkTwoHttpClientBridge.php

示例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();
     }
 }
开发者ID:bbeckman,项目名称:NDL-VuFind2,代码行数:21,代码来源:Connector.php

示例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());
 }
开发者ID:KBO-Techo-Dev,项目名称:MagazinePro-zf25,代码行数:21,代码来源:YumlController.php

示例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)));
 }
开发者ID:navidnahidi,项目名称:zf2_api,代码行数:38,代码来源:IndexController.php

示例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;
 }
开发者ID:continuousphp,项目名称:deploy-agent,代码行数:19,代码来源:Http.php

示例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;
 }
开发者ID:shivap87,项目名称:cost,代码行数:26,代码来源:RESTJSONManager.php

示例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;
 }
开发者ID:armenio,项目名称:armenio-zf2-geolocation-module,代码行数:32,代码来源:GeoLocation.php

示例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 . ')');
     }
 }
开发者ID:andreylis,项目名称:zf2-sms-adapters,代码行数:36,代码来源:LetsAdsAdapter.php

示例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;
 }
开发者ID:braghimsistemas,项目名称:zf2lib,代码行数:36,代码来源:ByjgClient.php

示例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;
 }
开发者ID:modelframework,项目名称:modelframework,代码行数:32,代码来源:Wepo.php


注:本文中的Zend\Http\Client::setMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。