当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::setHeaders方法代码示例

本文整理汇总了PHP中Zend\Http\Request::setHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setHeaders方法的具体用法?PHP Request::setHeaders怎么用?PHP Request::setHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Http\Request的用法示例。


在下文中一共展示了Request::setHeaders方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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());
 }
开发者ID:php-http,项目名称:zend-adapter,代码行数:30,代码来源:Client.php

示例2: pharAction

 public function pharAction()
 {
     $client = $this->serviceLocator->get('zendServerClient');
     $client = new Client();
     if (defined('PHAR')) {
         // the file from which the application was started is the phar file to replace
         $file = $_SERVER['SCRIPT_FILENAME'];
     } else {
         $file = dirname($_SERVER['SCRIPT_FILENAME']) . '/zs-client.phar';
     }
     $request = new Request();
     $request->setMethod(Request::METHOD_GET);
     $request->setHeaders(Headers::fromString('If-Modified-Since: ' . gmdate('D, d M Y H:i:s T', filemtime($file))));
     $request->setUri('https://github.com/zendtech/ZendServerSDK/raw/master/bin/zs-client.phar');
     //$client->getAdapter()->setOptions(array('sslcapath' => __DIR__.'/../../../certs/'));
     $client->setAdapter(new Curl());
     $response = $client->send($request);
     if ($response->getStatusCode() == 304) {
         return 'Already up-to-date.';
     } else {
         ErrorHandler::start();
         rename($file, $file . '.' . date('YmdHi') . '.backup');
         $handler = fopen($file, 'w');
         fwrite($handler, $response->getBody());
         fclose($handler);
         ErrorHandler::stop(true);
         return 'The phar file was updated successfully.';
     }
 }
开发者ID:alexb-uk,项目名称:ZendServerSDK,代码行数:29,代码来源:UpdateController.php

示例3: testRequestCanSetHeaders

 public function testRequestCanSetHeaders()
 {
     $request = new Request();
     $headers = new \Zend\Http\Headers();
     $ret = $request->setHeaders($headers);
     $this->assertInstanceOf('Zend\\Http\\Request', $ret);
     $this->assertSame($headers, $request->headers());
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:8,代码来源:RequestTest.php

示例4: testGet

 public function testGet()
 {
     $expectedDate = '2015-01-01';
     $headers = new Headers();
     $headers->addHeaderLine(sprintf('Cookie: %s=%s', TimetableCookieListener::COOKIE_NAME, $expectedDate));
     $request = new Request();
     $request->setHeaders($headers);
     $response = new Response();
     $listener = new TimetableCookieListener($request, $response);
     $event = new TimetableManagerEvent();
     $listener->getTime($event);
     $this->assertTrue($event->hasPointInTime());
     $this->assertEquals($expectedDate, $event->getPointInTime()->format('Y-m-d'));
 }
开发者ID:nathansalter,项目名称:verona,代码行数:14,代码来源:TimetableCookieListenerTest.php

示例5: 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());
 }
开发者ID:saxulum,项目名称:saxulum-http-client-adapter-zend,代码行数:18,代码来源:HttpClient.php

示例6: save

 /**
  * @param string $collectionPath
  * @param \SimpleXMLElement $element
  * @return \SimpleXMLElement | null
  */
 public function save($collectionPath, \SimpleXMLElement $element)
 {
     $uri = new Http($collectionPath);
     $request = new Request();
     $request->setMethod('PUT');
     $headers = new Headers();
     $headers->addHeader(new GenericHeader('Content-Type', 'application/xml'));
     $request->setHeaders($headers);
     $request->setContent($element->asXML());
     $response = $this->transport->put($uri, $request);
     $body = $response->getBody();
     if ($response->isClientError() || empty($body)) {
         return null;
     }
     return new \SimpleXMLElement($body);
 }
开发者ID:spalax,项目名称:zf2-client-moysklad,代码行数:21,代码来源:GenericMapper.php

示例7: testUnsupportedScheme

 public function testUnsupportedScheme()
 {
     $response = new Response();
     $headers = new Headers();
     $request = new Request();
     $headers->addHeaderLine('Authorization', 'NotSupportedScheme <followed by a space character');
     $request->setHeaders($headers);
     $a = new Adapter\Http($this->_digestConfig);
     $a->setDigestResolver($this->_digestResolver)->setRequest($request)->setResponse($response);
     $result = $a->authenticate();
     $this->assertEquals($result->getCode(), Authentication\Result::FAILURE_UNCATEGORIZED);
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:12,代码来源:ObjectTest.php

示例8: _doAuth

 /**
  * Acts like a client sending the given Authenticate header value.
  *
  * @param  string $clientHeader Authenticate header value
  * @param  string $scheme       Which authentication scheme to use
  * @return array Containing the result, the response headers, and the status
  */
 public function _doAuth($clientHeader, $scheme)
 {
     // Set up stub request and response objects
     $response = new Response();
     $response->setStatusCode(200);
     $headers = new Headers();
     $headers->addHeaderLine('Proxy-Authorization', $clientHeader);
     $headers->addHeaderLine('User-Agent', 'PHPUnit');
     $request = new Request();
     $request->setUri('http://localhost/');
     $request->setMethod('GET');
     $request->setHeaders($headers);
     // Select an Authentication scheme
     switch ($scheme) {
         case 'basic':
             $use = $this->_basicConfig;
             break;
         case 'digest':
             $use = $this->_digestConfig;
             break;
         case 'both':
         default:
             $use = $this->_bothConfig;
     }
     // Create the HTTP Auth adapter
     $a = new \Zend\Authentication\Adapter\Http($use);
     $a->setBasicResolver($this->_basicResolver);
     $a->setDigestResolver($this->_digestResolver);
     // Send the authentication request
     $a->setRequest($request);
     $a->setResponse($response);
     $result = $a->authenticate();
     $return = array('result' => $result, 'status' => $response->getStatusCode(), 'headers' => $response->getHeaders());
     return $return;
 }
开发者ID:nieldm,项目名称:zf2,代码行数:42,代码来源:ProxyTest.php

示例9: call

 /**
  * Call an api method
  *
  * @param $method
  * @param $params
  * @return mixed
  * @throws \Exception
  */
 public function call($method, $params)
 {
     $params['apikey'] = $this->getApiKey();
     $params = json_encode($params);
     $client = $this->getClient();
     $uri = $this->getBaseUri() . $method . '.json';
     $headers = new Headers();
     $headers->addHeaderLine('Accept-Encoding', 'identity');
     $headers->addHeaderLine('Content-Type', 'application/json');
     $headers->addHeaderLine('Accept', '*/*');
     $request = new Request();
     $request->setHeaders($headers);
     $request->setUri($uri);
     $request->setMethod('POST');
     $request->setContent($params);
     $response = $client->dispatch($request);
     if ($response->isSuccess()) {
         return json_decode($response->getContent(), true);
     } else {
         /*@TODO throw a more useful exception*/
         throw new \Exception('Request Failed');
     }
 }
开发者ID:carnage,项目名称:mailchimp,代码行数:31,代码来源:Api.php


注:本文中的Zend\Http\Request::setHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。