本文整理汇总了PHP中Zend\Http\Client::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getRequest方法的具体用法?PHP Client::getRequest怎么用?PHP Client::getRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Client
的用法示例。
在下文中一共展示了Client::getRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param HttpClient $httpClient
* @param HttpRequest $httpRequest
* @param ModuleOptions $moduleOptions
*/
public function __construct(HttpClient $httpClient, HttpRequest $httpRequest, ModuleOptions $moduleOptions)
{
$this->httpClient = $httpClient;
$this->httpRequest = $httpRequest;
$this->moduleOptions = $moduleOptions;
$this->httpClient->getRequest()->getHeaders()->addHeaders(array('Accept' => 'application/json'));
}
示例2: getHttpClient
/**
* Return the singleton instance of the HTTP Client. Note that
* the instance is reset and cleared of previous parameters and
* Authorization header values.
*
* @return Zend\Http\Client
*/
public static function getHttpClient()
{
if (!isset(self::$httpClient)) {
self::$httpClient = new HTTPClient();
} else {
$request = self::$httpClient->getRequest();
$headers = $request->getHeaders();
if ($headers->has('Authorization')) {
$auth = $headers->get('Authorization');
$headers->removeHeader($auth);
}
self::$httpClient->resetParameters();
}
return self::$httpClient;
}
示例3: getClientUrl
protected function getClientUrl(Client $client)
{
$uri = $client->getUri();
$query = $client->getRequest()->getQuery()->toString();
//$post = $client->getRequest()->getPost()->toString();
return $uri . '?' . $query;
}
示例4: 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);
}
}
示例5: injectHeaders
/**
* Inject header values into the client.
*
* @param array $headerValues
*/
private function injectHeaders(array $headerValues)
{
$headers = $this->client->getRequest()->getHeaders();
foreach ($headerValues as $name => $values) {
if (!is_string($name) || is_numeric($name) || empty($name)) {
throw new Exception\InvalidArgumentException(sprintf('Header names provided to %s::get must be non-empty, non-numeric strings; received %s', __CLASS__, $name));
}
if (!is_array($values)) {
throw new Exception\InvalidArgumentException(sprintf('Header values provided to %s::get must be arrays of values; received %s', __CLASS__, is_object($values) ? get_class($values) : gettype($values)));
}
foreach ($values as $value) {
if (!is_string($value) && !is_numeric($value)) {
throw new Exception\InvalidArgumentException(sprintf('Individual header values provided to %s::get must be strings or numbers; ' . 'received %s for header %s', __CLASS__, is_object($value) ? get_class($value) : gettype($value), $name));
}
$headers->addHeaderLine($name, $value);
}
}
}
示例6: connect
public function connect($uri, $post = false, $params = null)
{
$client = new Client($uri, array('timeout' => 600, 'sslverifypeer' => false));
if (!$post) {
$client->setParameterGet($params);
}
$request = $client->getRequest();
$response = $client->dispatch($request);
return $response;
}
示例7: testPostDataUrlEncoded
/**
* Test we can properly send POST parameters with
* application/x-www-form-urlencoded content type
*
* @dataProvider parameterArrayProvider
*/
public function testPostDataUrlEncoded($params)
{
$this->client->setUri($this->baseuri . 'testPostData.php');
$this->client->setEncType(HTTPClient::ENC_URLENCODED);
$this->client->setParameterPost($params);
$this->client->setMethod('POST');
$this->assertFalse($this->client->getRequest()->isPatch());
$res = $this->client->send();
$this->assertEquals(serialize($params), $res->getBody(), "POST data integrity test failed");
}
示例8: getRequest
/**
* Get Request
*
* @return Request
*/
public function getRequest()
{
if (empty($this->request)) {
$headers = new Headers();
$headers->addHeaders(array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
$request = parent::getRequest();
$request->setHeaders($headers);
$request->setMethod('POST');
}
return $this->request;
}
示例9: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Config');
$client = new Client();
$client->setOptions($config['oauth2']['httpClient']);
$token = $serviceLocator->get('OAuth2\\Token');
if ($token->isValid()) {
$client->getRequest()->getHeaders()->addHeaderLine('Authorization', "{$token->getTokenType()} {$token->getAccessToken()}");
}
return $client;
}
示例10: renderTemplate
/**
* @return string
*/
public function renderTemplate()
{
$config = $this->getServiceLocator()->get('Config');
if (!isset($config['wordpress']['template'])) {
throw new Exception\InvalidServiceException('No wordpress template defined');
}
$client = new Client($config['wordpress']['template']);
$client->setAdapter(new Client\Adapter\Curl());
$client->setMethod('GET');
$response = $client->send($client->getRequest());
return $response->getBody();
}
示例11: send
/**
* @param \SMS\Model\Number $from
* @param \SMS\Model\Number $to
* @param \SMS\Model\Content $content
* @return bool
* @throws \SMS\SMSException
* @throws \Exception
*/
public function send(Number $from, Number $to, Content $content)
{
$client = new Client();
$client->setUri($this->prepareUrl($from, $to, $content));
$client->setMethod('GET');
$client->setOptions(array('ssltransport' => 'tls', 'sslverify_peer' => false, 'sslcapath' => '/etc/ssl/certs'));
$response = $client->send($client->getRequest());
$responsejson = json_decode($response->getContent());
if ($responsejson->status != 100) {
throw new SMSException($response);
}
return true;
}
示例12: sendRequest
/**
* Perform a single OAI-PMH request.
*
* @param string $verb OAI-PMH verb to execute.
* @param array $params GET parameters for ListRecords method.
*
* @return string
*/
protected function sendRequest($verb, $params)
{
// Set up the request:
$this->client->resetParameters();
$this->client->setUri($this->baseUrl);
// Load request parameters:
$query = $this->client->getRequest()->getQuery();
$query->set('verb', $verb);
foreach ($params as $key => $value) {
$query->set($key, $value);
}
// Perform request:
return $this->client->setMethod('GET')->send();
}
示例13: execute
public function execute()
{
$payload = $this->getContent();
echo "processing >> " . $payload['page_url'] . " >> for id >> " . $payload['page_id'] . "\n";
/* @var \Application\V1\Entity\Pages $pageEntity */
$pageEntity = $this->entityManager->find('Application\\V1\\Entity\\Pages', $payload['page_id']);
try {
$this->httpClient->setUri($payload['page_url']);
$response = $this->httpClient->send();
$document = new Document($response->getBody());
$manager = $this->grabImageQueue->getJobPluginManager();
$jobs = [];
$parsedPageUrl = parse_url($this->httpClient->getRequest()->getUriString());
$cnt = 0;
/* @var \DOMElement $node */
foreach ($this->documentQuery->execute('//body//img', $document) as $node) {
$job = $manager->get('Application\\QueueJob\\GrabImage');
$src = $this->normalizeSchemeAndHost($node->getAttribute('src'), $parsedPageUrl['scheme'], $parsedPageUrl['host']);
$ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
$job->setContent(['image_src' => $src, 'image_ext' => $ext, 'page_id' => $payload['page_id']]);
$jobs[] = $job;
$cnt++;
}
if ($cnt < 1) {
$pageEntity->setStatus(PageInterface::STATUS_DONE);
} else {
$pageEntity->setStatus(PageInterface::STATUS_RUNNING);
}
$pageEntity->setPendingImagesCnt($cnt);
$pageEntity->setTotalImagesCnt($cnt);
$this->entityManager->flush();
foreach ($jobs as $job) {
$this->grabImageQueue->push($job);
}
echo "Jobs to push >> " . count($jobs) . " count pending images >>" . $cnt . "\n";
} catch (\Exception $e) {
echo 'Exception: >> ' . $e->getMessage();
$pageEntity->setErrorMessage($e->getMessage());
if ($pageEntity->getStatusNumeric() == PageInterface::STATUS_RECOVERING) {
$pageEntity->setStatus(PageInterface::STATUS_ERROR);
$this->entityManager->flush();
return WorkerEvent::JOB_STATUS_FAILURE;
} else {
$pageEntity->setStatus(PageInterface::STATUS_RECOVERING);
$this->entityManager->flush();
throw new ReleasableException(array('priority' => 10, 'delay' => 15));
}
}
}
示例14: run
public static function run(Service\ServiceAbstract $service)
{
$request = new Request();
$client = new Client();
$adapter = new Adapter\Curl();
$request->setMethod('GET');
$client->setAdapter($adapter);
foreach ($service as $url) {
if (!is_string($url)) {
continue;
}
$client->setUri($url);
$response = $client->send($client->getRequest());
echo $url . " --> " . $response->getStatusCode();
}
}
示例15: githubContributorsAction
public function githubContributorsAction()
{
$this->verifyConsole();
$width = $this->console->getWidth();
$this->console->writeLine('Fetching GitHub Contributors', Color::GREEN);
$client = new HttpClient();
$client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
$client->setUri('https://api.github.com/repos/zendframework/zf2/contributors');
if (isset($this->config['github_token']) && $this->config['github_token']) {
$httpRequest = $client->getRequest();
$httpRequest->getHeaders()->addHeaderLine('Authorization', 'token ' . $this->config['github_token']);
}
$response = $client->send();
if (!$response->isSuccess()) {
// report failure
$message = $response->getStatusCode() . ': ' . $response->getReasonPhrase();
$this->reportError($width, 0, $message);
return;
}
$body = $response->getBody();
$contributors = json_decode($body, true);
$total = count($contributors);
foreach ($contributors as $i => $contributor) {
$message = sprintf(' Processing %d/%d', $i, $total);
$this->console->write($message);
$client->setUri("https://api.github.com/users/{$contributor['login']}");
$response = $client->send();
if (!$response->isSuccess()) {
// report failure
$error = $response->getStatusCode() . ': ' . $response->getReasonPhrase();
$this->reportError($width, strlen($message), $error);
}
$body = $response->getBody();
$userInfo = json_decode($body, 1);
$contributors[$i]['user_info'] = $userInfo;
$this->reportSuccess($width, strlen($message));
}
$this->console->writeLine(str_repeat('-', $width));
$message = 'Writing file';
$this->console->write($message, Color::BLUE);
// file_put_contents(__DIR__ . '/../../../data/contributors/contributors.pson', serialize($contributors));
$path = $this->config['github-contributors']['output_file'];
file_put_contents($path, serialize($contributors));
$this->reportSuccess($width, strlen($message));
$this->console->writeLine(sprintf('File written to %s', $path));
}