リクエストヘッダ

リクエストヘッダ – HTTP リクエストに付加的なヘッダを追加する

リクエストヘッダの追加方法

カスタムリクエストヘッダの追加

以下の例では、HTTP ヘッダ X-PHP-Version が HTTP リクエストに追加されます。このヘッダの値は、 HTTP_Request インスタンスが動作している PHP インタプリタのバージョン文字列です。

<?php
require_once "HTTP/Request.php";

$req =& new HTTP_Request("http://example.com/");
$req->addHeader("X-PHP-Version"phpversion());

$response $req->sendRequest();

if (
PEAR::isError($response)) {
    echo 
$response->getMessage();
} else {
    echo 
$req->getResponseBody();
}
?>

HTTP_Request オブジェクトに追加されたヘッダは、 sendRequest() がコールされる前に removeHeader() で削除することができます。

HTTP 経由でファイルをアップロードする (Previous) HTTP プロキシを利用する (Next)
Last updated: Sun, 29 Aug 2010 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.