本文整理汇总了PHP中Zend\Http\Client::setParameterPOST方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setParameterPOST方法的具体用法?PHP Client::setParameterPOST怎么用?PHP Client::setParameterPOST使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Client
的用法示例。
在下文中一共展示了Client::setParameterPOST方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: writeStream
/**
* Write using a stream
*
* @param $path
* @param $resource
* @param null $config
* @return array|bool
*/
public function writeStream($path, $resource, Config $config)
{
$username = 'admin';
$password = '12345678';
$auth = base64_encode($username . ':' . $password);
$this->client->setUri('http://192.168.10.47/api/wstest/upload/fg');
// $this->client->setUri('http://files.local/api/v2/fs');
$this->client->setMethod('POST');
$headers = ['Accept' => '*/*', 'Cache-Control' => 'no-cache', 'Authorization' => 'Basic ' . $auth, 'X-File-Name' => 'todo.txt', 'Content-Type' => 'application/x-www-form-urlencoded'];
$this->client->setHeaders($headers);
file_put_contents('tmp', $resource);
// $this->client->setFileUpload('todo.txt', 'todo_txt', $resource);
$text = 'this is some plain text';
$this->client->setFileUpload('some_text.txt', 'some_text_txt', $text, 'text/plain');
prn($this->client->send()->getContent());
exit;
$location = $this->applyPathPrefix($path);
$config = Util::ensureConfig($config);
$this->ensureDirectory(dirname($location));
$this->client->setMethod('POST');
$this->client->setUri($this->api_url);
$this->client->setParameterPOST(array_merge($this->auth_param, ['filename' => $path]));
$this->client->setHeaders(['wp_path' => $path]);
file_put_contents('tmp', $resource);
$this->client->setFileUpload('tmp', 'form');
$response = $this->client->send();
$path = json_decode($response->getContent())->file_id;
$type = 'wepo_fs';
$result = compact('contents', 'type', 'size', 'path');
if ($visibility = $config->get('visibility')) {
$result['visibility'] = $visibility;
}
return $result;
}
示例3: 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;
}
示例4: 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;
}
示例5: write
/**
* {@inheritdoc}
*/
public function write($path, $contents, Config $config)
{
$location = $this->applyPathPrefix($path);
prn($path, $contents, $config, $location, dirname($location));
$this->client->setMethod('POST');
$this->client->setUri($this->api_url);
$this->client->setParameterPOST(array_merge($this->auth_param, ['filename' => $path]));
file_put_contents('tmp', $contents);
$this->client->setFileUpload('tmp', 'form');
$response = $this->client->send();
if ($response->getStatusCode() != 200) {
throw new \Exception(json_decode($response->getBody())->message);
}
prn($response->getContent());
return json_decode($response->getContent())->data->{$filename};
$location = $this->applyPathPrefix($path);
$this->client->request('PUT', $location, $contents);
$result = compact('path', 'contents');
if ($config->get('visibility')) {
throw new LogicException(__CLASS__ . ' does not support visibility settings.');
}
return $result;
}
示例6: indexAction
public function indexAction()
{
if ($this->request->isPost()) {
$cnpj = $this->request->getPost('cnpj');
$client = new HttpClient();
$client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
$method = $this->params()->fromQuery('method', 'post');
$client->setUri("http://www.sintegra.es.gov.br/resultado.php");
$client->setMethod('POST');
$client->setParameterPOST(array('num_cnpj' => $cnpj, 'botao' => 'Consultar'));
$response = $client->send();
if (!$response->isSuccess()) {
$message = $response->getStatusCode() . ': ' . $response->getReasonPhrase();
$response = $this->getResponse();
$response->setContent($message);
}
$body = $response->getBody();
//$response->setContent($body);
/*$dom = new Query($body);
$results = $dom->execute('.resultado');*/
$view_params = array('response' => $body);
return new ViewModel($view_params);
}
}
示例7: 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;
}