當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。