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


PHP Client::setParameterGET方法代码示例

本文整理汇总了PHP中Zend\Http\Client::setParameterGET方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setParameterGET方法的具体用法?PHP Client::setParameterGET怎么用?PHP Client::setParameterGET使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Http\Client的用法示例。


在下文中一共展示了Client::setParameterGET方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: indexAction

 public function indexAction()
 {
     $client = new HttpClient();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $method = $this->params()->fromRoute('param', 'get-list');
     $client->setUri('http://localhost/album-rest');
     switch ($method) {
         case 'get':
             $id = $this->params()->fromRoute('id', 2);
             $client->setMethod('GET');
             $client->setParameterGET(array('id' => $id));
             break;
         case 'get-list':
             $client->setMethod('GET');
             break;
         case 'create':
             $client->setMethod('POST');
             $client->setParameterPOST(array('title' => 'Bob Marley LIVE', 'artist' => 'Bob Marley'));
             break;
         case 'update':
             $id = $this->params()->fromRoute('id', 2);
             $data = array('title' => 'Show 90 Anos Ao Vivo', 'artist' => 'Zeze di Camargo & Luciano');
             $client->setMethod('PUT');
             $client->setParameterPOST($data);
             $client->setParameterGET(array('id' => $id));
             break;
         case 'delete':
             $id = $this->params()->fromRoute('id', 2);
             $client->setMethod('DELETE');
             $client->setParameterGET(array('id' => $id));
             break;
     }
     //send request
     $response = $client->send();
     if (!$response->isSuccess()) {
         //error
         $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:ptcampos,项目名称:zend2-RESTful-example,代码行数:46,代码来源:RequestToAPIController.php

示例3: curl

 public function curl($url, array $params, $method = "POST")
 {
     $client = new HttpClient();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $client->setUri($url);
     $client->setOptions(array('maxredirects' => 0, 'timeout' => 30));
     $client->setMethod($method);
     $client->setHeaders(array('username: apiuser', 'password: 123456'));
     //if(!empty($params)) {
     if ($method == "POST" || $method == "PUT" || $method == "DELETE") {
         $client->setParameterPOST($params);
     } else {
         $client->setParameterGET($params);
     }
     //}
     $response = $client->send();
     return $response;
 }
开发者ID:riteshkmr33,项目名称:ovessnce,代码行数:18,代码来源:Api.php

示例4: indexAction

 public function indexAction()
 {
     $client = new HttpClient();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $method = $this->params()->fromQuery('method', 'get');
     $client->setUri('http://posterlab.skilla.com/relatori/rest/ejemplo-servidor-restful');
     switch ($method) {
         case 'get-list':
             $client->setMethod('GET');
             break;
         case 'get':
             $client->setMethod('GET');
             $client->setParameterGET(array('id' => 4));
             break;
         case 'create':
             $client->setMethod('POST');
             $client->setParameterPOST(array('data' => 'Programacion Java SE'));
             break;
         case 'update':
             $data = array('data' => 'Curso Spring Framework');
             $adapter = $client->getAdapter();
             $adapter->connect('posterlab.skilla.com', 80);
             $uri = $client->getUri() . '/2';
             // Enviamos con Method PUT, con el parametro $data
             $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', 'application/json; charset=utf-8');
             $response->setContent($content);
             return $response;
         case 'delete':
             $adapter = $client->getAdapter();
             $adapter->connect('posterlab.skilla.com', 80);
             $uri = $client->getUri() . '/1';
             //enviamos param id = 1
             // Enviamos con Method DELETE
             $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', 'application/json; charset=utf-8');
             $response->setContent($content);
             return $response;
         default:
             $client->setMethod('GET');
             break;
     }
     //enviamos get/get-list/create
     $response = $client->send();
     if (!$response->isSuccess()) {
         // reportamos la falla
         $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:sebaxplace,项目名称:skilla-local,代码行数:62,代码来源:EjemploClienteRestfulController.php


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