PHP Velho Oeste 2024

HttpRequest::setHeaders

(PECL pecl_http >= 0.12.0)

HttpRequest::setHeadersSet headers

설명

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

Set request header name/value pairs.

인수

headers

an associative array as parameter containing header name/value pairs; if empty or omitted, all previously set headers will be unset

반환값

성공 시 TRUE를, 실패 시 FALSE를 반환합니다.

add a note add a note

User Contributed Notes 1 note

up
0
quickshiftin at gmail dot com
15 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
To Top