CURL コンテキストオプション
CURL コンテキストオプション — CURL コンテキストオプションの一覧
説明
CURL コンテキストオプションは、
CURL 拡張モジュールのコンパイル時に
--with-curlwrappers オプションを指定すると使用可能となります。
オプション
method
string
GET
、POST
あるいはその他リモートサーバーがサポートする HTTP メソッド。
デフォルトは GET
です。
header
string
リクエスト時に送信する追加のヘッダ。このオプションの値は
(User-agent:
や Host:
、
Authentication:
といった)
他の値を上書きします。
user_agent
string
User-Agent: ヘッダで送信する値。
デフォルトでは、php.ini
の
user_agent
の設定内容を使用します。
content
string
ヘッダの後に送信する追加データ。このオプションは
GET
あるいは HEAD
リクエストでは使用しません。
proxy
string
プロキシサーバーのアドレスを表す URI
(tcp://proxy.example.com:5100
など)。
max_redirects
int
リダイレクトを追いかける最大数。1
以下を指定した場合は、リダイレクトを追跡しません。
デフォルトは 20
です。
curl_verify_ssl_host
bool
ホストを検証する。
デフォルトは false
です。
注意:
このオプションは、http および ftp の両方のプロトコルラッパーで使用可能です。
curl_verify_ssl_peer
bool
SSL 証明書の検証を要求する。
デフォルトは false
です。
注意:
このオプションは、http および ftp の両方のプロトコルラッパーで使用可能です。
例
例1 ページの取得と POST データの送信
<?php$postdata = http_build_query( array( 'var1' => 'some content', 'var2' => 'doh' ));$opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ));$context = stream_context_create($opts);$result = file_get_contents('http://example.com/submit.php', false, $context);?>