downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

HttpRequest::setMethod> <HttpRequest::setCookies
[edit] Last updated: Fri, 17 May 2013

view this page in

HttpRequest::setHeaders

(PECL pecl_http >= 0.12.0)

HttpRequest::setHeadersDéfinit un en-tête

Description

public bool HttpRequest::setHeaders ([ array $headers ] )

Définit des en-têtes.

Liste de paramètres

headers

un tableau associatif contenant les paires nom/valeur des en-têtes ; si ce paramètre est vide ou omis, tous les en-têtes précédemment définis seront effacés.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès ou FALSE si une erreur survient.



add a note add a note User Contributed Notes HttpRequest::setHeaders - [1 notes]
up
0
quickshiftin at gmail dot com
4 years ago
note: you should not put a colon in the keys of the arrays you pass this method, it will do that for you.  and if you do put colons in the array keys, the resultant headers will have 2 colons beside one another.

so for example,
<?php
$httpRequest
->setHeaders(array('User-Agent' => 'Mozilla/1.22 (compatible; MSIE 5.01; PalmOS 3.0) EudoraWeb 2'));
?>

will result in
User-Agent: Mozilla/1.22 (compatible; MSIE 5.01; PalmOS 3.0) EudoraWeb 2

<?php
$httpRequest
->setHeaders(array('User-Agent:' => 'Mozilla/1.22 (compatible; MSIE 5.01; PalmOS 3.0) EudoraWeb 2'));
?>

will result in
User-Agent:: Mozilla/1.22 (compatible; MSIE 5.01; PalmOS 3.0) EudoraWeb 2

 
show source | credits | stats | sitemap | contact | advertising | mirror sites