本文整理汇总了PHP中Zend\Http\Request::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getHeaders方法的具体用法?PHP Request::getHeaders怎么用?PHP Request::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Request
的用法示例。
在下文中一共展示了Request::getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getServer
/**
* (non-PHPdoc)
* @see Tinebase_Server_Plugin_Interface::getServer()
*/
public static function getServer(\Zend\Http\Request $request)
{
/**************************** JSON API *****************************/
if ($request->getHeaders('X-TINE20-REQUEST-TYPE') && $request->getHeaders('X-TINE20-REQUEST-TYPE')->getFieldValue() === 'JSON' || $request->getHeaders('CONTENT-TYPE') && substr($request->getHeaders('CONTENT-TYPE')->getFieldValue(), 0, 16) === 'application/json' || $request->getPost('requestType') === 'JSON' || $request->getHeaders('ACCESS-CONTROL-REQUEST-METHOD')) {
return new Tinebase_Server_Json();
}
}
示例2: testProcessPostRequestReturnsToken
public function testProcessPostRequestReturnsToken()
{
$request = new Request();
$request->setMethod('post');
$parameters = new ParameterDataContainer();
$parameters->setBodyParam('format', 'ZIP');
$event = new MvcEvent();
$event->setParam('ZFContentNegotiationParameterData', $parameters);
$request->getHeaders()->addHeaderLine('Content-Type', 'application/json');
$request->getHeaders()->addHeaderLine('Accept', 'application/json');
$this->controller->setRequest($request);
$this->controller->setEvent($event);
$cwd = getcwd();
chdir(__DIR__ . '/TestAsset');
$result = $this->controller->indexAction();
chdir($cwd);
$this->assertInternalType('array', $result);
$this->assertTrue(isset($result['token']));
$this->assertTrue(isset($result['format']));
$package = sys_get_temp_dir() . '/apigility_' . $result['token'] . '.' . $result['format'];
$this->assertTrue(file_exists($package));
return $result;
}
示例3: testFormPluginIsNotCalledIfAjaxRequest
public function testFormPluginIsNotCalledIfAjaxRequest()
{
$headers = $this->request->getHeaders();
$headers->addHeaderLine('X_REQUESTED_WITH', 'XMLHttpRequest');
$this->target->form('elements');
$result = $this->target->getResult();
$this->assertEmpty($result);
}
示例4: fromZend
/**
* Convert a Zend\Http\Response in a PSR-7 response, using zend-diactoros
*
* @param ZendRequest $zendRequest
* @return ServerRequest
*/
public static function fromZend(ZendRequest $zendRequest)
{
$body = new Stream('php://memory', 'wb+');
$body->write($zendRequest->getContent());
$headers = empty($zendRequest->getHeaders()) ? [] : $zendRequest->getHeaders()->toArray();
$query = empty($zendRequest->getQuery()) ? [] : $zendRequest->getQuery()->toArray();
$post = empty($zendRequest->getPost()) ? [] : $zendRequest->getPost()->toArray();
$files = empty($zendRequest->getFiles()) ? [] : $zendRequest->getFiles()->toArray();
$request = new ServerRequest([], self::convertFilesToUploaded($files), $zendRequest->getUriString(), $zendRequest->getMethod(), $body, $headers);
$request = $request->withQueryParams($query);
return $request->withParsedBody($post);
}
示例5: getServer
/**
* (non-PHPdoc)
* @see Tinebase_Server_Plugin_Interface::getServer()
*/
public static function getServer(\Zend\Http\Request $request)
{
/**************************** SNOM API *****************************/
if ($request->getHeaders('USER-AGENT') && preg_match('/^Mozilla\\/4\\.0 \\(compatible; (snom...)\\-SIP (\\d+\\.\\d+\\.\\d+)/i', $request->getHeaders('USER-AGENT')->getFieldValue())) {
return new Voipmanager_Server_Snom();
/**************************** ASTERISK API *****************************/
} else {
if ($request->getHeaders('USER-AGENT') && $request->getHeaders('USER-AGENT')->getFieldValue() === 'asterisk-libcurl-agent/1.0') {
return new Voipmanager_Server_Asterisk();
}
}
}
示例6: testOnRenderErrorCreatesAnApiProblemResponse
public function testOnRenderErrorCreatesAnApiProblemResponse()
{
$response = new Response();
$request = new Request();
$request->getHeaders()->addHeaderLine('Accept', 'application/json');
$event = new MvcEvent();
$event->setError(Application::ERROR_EXCEPTION);
$event->setRequest($request);
$event->setResponse($response);
$this->listener->onRenderError($event);
$this->assertTrue($event->propagationIsStopped());
$this->assertSame($response, $event->getResponse());
$this->assertEquals(406, $response->getStatusCode());
$headers = $response->getHeaders();
$this->assertTrue($headers->has('Content-Type'));
$this->assertEquals('application/problem+json', $headers->get('content-type')->getFieldValue());
$content = json_decode($response->getContent(), true);
$this->assertArrayHasKey('status', $content);
$this->assertArrayHasKey('title', $content);
$this->assertArrayHasKey('describedBy', $content);
$this->assertArrayHasKey('detail', $content);
$this->assertEquals(406, $content['status']);
$this->assertEquals('Not Acceptable', $content['title']);
$this->assertContains('www.w3.org', $content['describedBy']);
$this->assertContains('accept', $content['detail']);
}
示例7: 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;
}
示例8: PlanJSONManager
function PlanJSONManager($action, $url, $requestjson, $uid)
{
$request = new Request();
$request->getHeaders()->addHeaders(array('Content-Type' => 'application/json; charset=UTF-8'));
//$url="";
try {
$request->setUri($url);
$request->setMethod($action);
$client = new Client();
if ($action == 'PUT' || $action == 'POST') {
$client->setUri($url);
$client->setMethod($action);
$client->setRawBody($requestjson);
$client->setEncType('application/json');
$response = $client->send();
return $response;
} else {
$response = $client->dispatch($request);
//var_dump(json_decode($response->getBody(),true));
return $response;
}
} catch (\Exception $e) {
$e->getTrace();
}
return null;
}
示例9: 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'];
}
示例10: call
public function call($params = null)
{
$request = new Request();
$request->getHeaders()->addHeaders(array('Accept' => 'application/json'));
if (!is_null($this->bearer_token)) {
$request->getHeaders()->addHeaders(array('Authorization' => $this->bearer_token));
}
$request->setUri($this->endpoint);
$request->setMethod($this->method);
if (!is_null($params)) {
$request->getPost()->fromArray($params);
}
$client = new Client($this->endpoint, array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl'));
$response = $client->dispatch($request);
return Json::decode($response->getBody(), Json::TYPE_ARRAY);
}
示例11: request
/**
* @inheritdoc
*/
public function request(array $params)
{
try {
$request = new Request();
$headers = $request->getHeaders();
$request->setUri($params['url']);
$headers->addHeaderLine('Accept-Encoding', 'gzip,deflate');
if ($params['config']->isAuthenticationPossible() === true && $this->option['keys']['public'] !== null && $this->option['keys']['private'] !== null) {
/**
* Note: DATE_RFC1123 my not be RFC 1123 compliant, depending on your platform.
* @link http://www.php.net/manual/de/function.gmdate.php#25031
*/
$date = gmdate('D, d M Y H:i:s \\G\\M\\T');
$path = $request->getUri()->getPath();
$headers->addHeaderLine('Date', $date);
$headers->addHeaderLine('Authorization', $this->signRequest('GET', $date, $path));
}
if (isset($params['lastmodified'])) {
$headers->addHeaderLine('If-Modified-Since', $params['lastmodified']);
}
$response = $this->client->send($request);
$body = $response->getBody();
$headers = null;
if ($this->option['responseheader']) {
$headers = $response->getHeaders()->toArray();
$this->lastResponseHeaders = $headers;
}
} catch (\Exception $e) {
throw new ClientException('Client exception catched, use getPrevious().', 0, $e);
}
return $this->createResponse($params['config']->isJson(), $response->getStatusCode(), $body, $headers);
}
示例12: callServer
public function callServer($method, $params)
{
// Get the URI and Url Elements
$apiUrl = $this->generateUrl($method);
$requestUri = $apiUrl['uri'];
// Convert the params to something MC can understand
$params = $this->processParams($params);
$params["apikey"] = $this->getConfig('apiKey');
$request = new Request();
$request->setMethod(Request::METHOD_POST);
$request->setUri($requestUri);
$request->getHeaders()->addHeaders(array('Host' => $apiUrl['host'], 'User-Agent' => 'MCAPI/' . $this->getConfig('apiVersion'), 'Content-type' => 'application/x-www-form-urlencoded'));
$client = new Client();
$client->setRequest($request);
$client->setParameterPost($params);
$result = $client->send();
if ($result->getHeaders()->get('X-MailChimp-API-Error-Code')) {
$error = unserialize($result->getBody());
if (isset($error['error'])) {
throw new MailchimpException('The mailchimp API has returned an error (' . $error['code'] . ': ' . $error['error'] . ')');
return false;
} else {
throw new MailchimpException('There was an unspecified error');
return false;
}
}
return $result->getBody();
}
示例13: testAtomAcceptHeaderSelectsFeedStrategy
public function testAtomAcceptHeaderSelectsFeedStrategy()
{
$request = new HttpRequest();
$request->getHeaders()->addHeaderLine('Accept', 'application/atom+xml');
$this->event->setRequest($request);
$result = $this->strategy->selectRenderer($this->event);
$this->assertSame($this->renderer, $result);
}
示例14: preparePostRequest
private function preparePostRequest($post)
{
$postRequest = new Request();
$postRequest->setMethod(Request::METHOD_POST);
$postRequest->setPost($post);
$postRequest->setUri($this->url);
$postRequest->getHeaders()->addHeaders(['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8']);
return $postRequest;
}
示例15: createAjaxRequestWithSpecificPostData
public function createAjaxRequestWithSpecificPostData($postData)
{
$request = new Request();
$request->getHeaders()->addHeaders(['X_REQUESTED_WITH' => 'XMLHttpRequest']);
$parameters = new \Zend\Stdlib\Parameters();
$parameters->fromArray($postData);
$request->setPost($parameters);
return $request;
}