本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}