本文整理汇总了PHP中Zend\Http\Client::send方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::send方法的具体用法?PHP Client::send怎么用?PHP Client::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Client
的用法示例。
在下文中一共展示了Client::send方法的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;
}
示例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);
}
}
示例3: sendRequest
/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request)
{
$request = $this->sanitizeRequest($request);
$headers = new Headers();
foreach ($request->getHeaders() as $key => $value) {
$headers->addHeader(new GenericHeader($key, $request->getHeaderLine($key)));
}
$zendRequest = new Request();
$zendRequest->setMethod($request->getMethod());
$zendRequest->setUri((string) $request->getUri());
$zendRequest->setHeaders($headers);
$zendRequest->setContent($request->getBody()->getContents());
$options = ['httpversion' => $request->getProtocolVersion()];
if (extension_loaded('curl')) {
$options['curloptions'] = [CURLOPT_HTTP_VERSION => $this->getProtocolVersion($request->getProtocolVersion())];
}
$this->client->setOptions($options);
if ($this->client->getAdapter() instanceof ZendClient\Adapter\Curl && $request->getMethod()) {
$request = $request->withHeader('Content-Length', '0');
}
try {
$zendResponse = $this->client->send($zendRequest);
} catch (RuntimeException $exception) {
throw new NetworkException($exception->getMessage(), $request, $exception);
}
return $this->responseFactory->createResponse($zendResponse->getStatusCode(), $zendResponse->getReasonPhrase(), $zendResponse->getHeaders()->toArray(), $zendResponse->getContent(), $zendResponse->getVersion());
}
示例4: proceed
/**
* @param Request $request
* @return Response
*/
protected function proceed(Http $httpUri, Request $request)
{
$httpUri = $httpUri->parse($this->moduleOptions->getApiUrl() . $httpUri->toString());
$request->setUri($httpUri);
$this->httpClient->setAuth($this->moduleOptions->getUserName(), $this->moduleOptions->getPassword());
$this->httpClient->setOptions(array('sslverifypeer' => false));
return $this->httpClient->send($request);
}
示例5: doSendInternalRequest
/**
* {@inheritdoc}
*/
protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
{
$this->client->resetParameters(true)->setOptions(array('httpversion' => $internalRequest->getProtocolVersion(), 'timeout' => $this->getConfiguration()->getTimeout(), 'maxredirects' => 0))->setUri($url = (string) $internalRequest->getUrl())->setMethod($internalRequest->getMethod())->setHeaders($this->prepareHeaders($internalRequest))->setRawBody($this->prepareBody($internalRequest));
try {
$response = $this->client->send();
} catch (\Exception $e) {
throw HttpAdapterException::cannotFetchUrl($url, $this->getName(), $e->getMessage());
}
return $this->getConfiguration()->getMessageFactory()->createResponse($response->getStatusCode(), $response->getReasonPhrase(), $response->getVersion(), $response->getHeaders()->toArray(), BodyNormalizer::normalize(function () use($response) {
return $response instanceof Stream ? $response->getStream() : $response->getBody();
}, $internalRequest->getMethod()));
}
示例6: executeQuery
/**
* @param $select
* @param $from
* @param $where
* @param $format
*/
public function executeQuery($select, $from, $where, $format = 'json')
{
$yql_query = "select {$select} from {$from} where {$where} ";
$this->client->setParameterGet(array('q' => $yql_query, 'format' => $format));
$response = $this->client->send();
/* @var $response \Zend\Http\Response */
if ($response->isSuccess()) {
return $response->getBody();
} else {
throw new \Exception('Error - Response code: ' . $response->getStatusCode() . ' - query - ' . $yql_query);
}
}
示例7: 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()));
}
示例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());
}
示例9: request
/**
* @param Request $request
* @return Response
*/
public function request(Request $request)
{
$headers = new Headers();
$headers->addHeaders($request->getHeaders());
$zendRequest = new ZendRequest();
$zendRequest->setVersion($request->getProtocolVersion());
$zendRequest->setMethod($request->getMethod());
$zendRequest->setUri((string) $request->getUrl());
$zendRequest->setHeaders($headers);
$zendRequest->setContent($request->getContent());
/** @var ZendResponse $zendResponse */
$zendResponse = $this->client->send($zendRequest);
return new Response((string) $zendResponse->getVersion(), $zendResponse->getStatusCode(), $zendResponse->getReasonPhrase(), $zendResponse->getHeaders()->toArray(), $zendResponse->getContent());
}
示例10: saveVisitorData
/**
* Make a remote call to freegeoip.net to detect country of current customer session and store it into session
*
* @return $this
*/
public function saveVisitorData($observer)
{
$clientIP = $this->_request->getClientIp();
$httpClient = new Client();
$clientIP = $this->getRandomeIp($clientIP);
$uri = self::URL_GEO_IP_SITE . $clientIP;
$httpClient->setUri($uri);
$httpClient->setOptions(array('timeout' => 30));
try {
$response = JsonDecoder::decode($httpClient->send()->getBody());
$this->_customerSession->setVisitorData($response);
//save to database
$currenttime = date('Y-m-d H:i:s');
$model = $this->_objectManager->create('Bluecom\\Freegeoip\\Model\\Visitor');
$model->setData('visitor_ip', $response->ip);
$model->setData('country_code', $response->country_code);
$model->setData('country_name', $response->country_name);
$model->setData('region_code', $response->region_code);
$model->setData('region_name', $response->region_name);
$model->setData('city', $response->city);
$model->setData('zip_code', $response->zip_code);
$model->setData('latitude', $response->latitude);
$model->setData('longitude', $response->longitude);
$model->setData('metro_code', $response->metro_code);
$model->setData('browser', $_SERVER['HTTP_USER_AGENT']);
$model->setData('os', php_uname());
$model->setData('created', $currenttime);
$model->save();
} catch (\Exception $e) {
$this->_logger->critical($e);
}
return $this;
}
示例11: _upload
/**
* @return Model\File[]
* @throws \Zend_Http_Client_Exception
*/
private function _upload()
{
$this->_client->setUri(implode('/', [self::getConfig()['uri'], 'file/upload']));
$this->_client->setMethod('POST');
$filesInfo = json_decode($this->_client->send()->getBody(), true);
return $this->_convertFilesInfoToObject($filesInfo);
}
示例12: doRequest
/**
* @todo whats wrong with SSL?
* @return array
*/
public function doRequest()
{
$url = 'https://www.mvg.de/.rest/betriebsaenderungen/api/interruptions';
$client = new Client($url, array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE)));
$client->setMethod(\Zend\Http\Request::METHOD_GET);
return ZendJson::decode($client->send()->getBody());
}
示例13: persist
public function persist(HelpReport $report)
{
$data = ['description' => 'Report generated via Ocramius CLI', 'files' => ['report.json' => ['content' => json_encode($report)]], 'public' => false];
$request = new Request();
$request->setUri('https://api.github.com/gists');
$request->setContent(json_encode($data));
$request->setMethod(Request::METHOD_POST);
$request->getHeaders()->addHeader(ContentType::fromString('Content-Type: application/json'));
$request->getHeaders()->addHeaderLine('X-Requested-With: Ocramius CLI');
$response = $this->client->send($request);
if (!$response->isSuccess()) {
throw new \UnexpectedValueException('Could not obtain a valid GIST from the github API');
}
$response = json_decode($response->getBody(), true);
return $response['html_url'];
}
示例14: findRegion
public function findRegion($country, $query)
{
$request = new Request();
$request->setMethod(Request::METHOD_GET);
foreach ($query as $key => $value) {
$request->getQuery()->set($key, $value);
}
$request->getHeaders()->addHeaderLine('Accept', 'application/json');
switch ($country) {
case 'CH':
$request->setUri($this->config['url'] . '/ch-region');
break;
default:
$request->setUri($this->config['url'] . '/ch-region');
break;
}
$client = new Client();
$response = $client->send($request);
$body = $response->getBody();
$result = json_decode($body, true);
if ($result) {
return $result['_embedded']['ch_region'];
}
/*echo "<textarea cols='100' rows='30' style='position:relative; z-index:10000; width:inherit; height:200px;'>";
print_r($body);
echo "</textarea>";
die();*/
return null;
}
示例15: 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;
}