mirror of
https://github.com/php/doc-ja.git
synced 2026-03-23 22:52:11 +01:00
352 lines
11 KiB
XML
352 lines
11 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 3abd17e61d5022d503604cc06894254e3281acf5 Maintainer: takagi Status: ready -->
|
|
<!-- Credits: mumumu -->
|
|
|
|
<refentry xml:id="context.http" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" annotations="verify_info:false" role="stream_context_option">
|
|
<refnamediv>
|
|
<refname>HTTP コンテキストオプション</refname>
|
|
<refpurpose>HTTP コンテキストオプションの一覧</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<para>
|
|
<literal>http://</literal> および <literal>https://</literal>
|
|
トランスポート用のコンテキストオプションです。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="options"><!-- {{{ -->
|
|
&reftitle.options;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry xml:id="context.http.method">
|
|
<term>
|
|
<parameter>method</parameter>
|
|
<type>string</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
リモートサーバーでサポートされる <constant>GET</constant>、
|
|
<constant>POST</constant> あるいはその他の HTTP メソッド。
|
|
</para>
|
|
<para>
|
|
デフォルトは <constant>GET</constant> です。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.header">
|
|
<term>
|
|
<parameter>header</parameter>
|
|
<type>array</type> あるいは <type>string</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
リクエストに付加されるヘッダ。ここで指定した値が
|
|
(<literal>User-agent:</literal>、<literal>Host:</literal>、
|
|
および <literal>Authentication:</literal> などの)
|
|
他の値を上書きすることもあります。
|
|
これは、後に<literal>Location:</literal>
|
|
によってリダイレクトが行われる場合でも同様です。
|
|
よって、<parameter>follow_location</parameter> が有効になっている場合、
|
|
<literal>Host:</literal> ヘッダを設定することはお勧めしません。
|
|
</para>
|
|
<para>
|
|
文字列の値は、<literal>Key: value</literal> のペアを
|
|
<literal>\r\n</literal> で区切ったものにすべきです。
|
|
たとえば、
|
|
<literal>"Content-Type: application/json\r\nConnection: close"</literal>
|
|
のようにします。
|
|
配列の値は、<literal>Key: value</literal> のペアのリストにすべきです。
|
|
たとえば、
|
|
<literal>["Content-Type: application/json", "Connection: close"]</literal>
|
|
のようにします。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.user-agent">
|
|
<term>
|
|
<parameter>user_agent</parameter>
|
|
<type>string</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
<literal>User-Agent:</literal> ヘッダとして送信する値。上で説明した
|
|
<literal>header</literal> オプションで user-agent が
|
|
定義されて<emphasis>いない</emphasis>場合のみ使用されます。
|
|
</para>
|
|
<para>
|
|
デフォルトでは、&php.ini; の
|
|
<link linkend="ini.user-agent">user_agent</link>
|
|
の設定内容を使用します。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.content">
|
|
<term>
|
|
<parameter>content</parameter>
|
|
<type>string</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
ヘッダの後に送信する追加データ。通常、POST または PUT
|
|
リクエストの際に使用されます。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.proxy">
|
|
<term>
|
|
<parameter>proxy</parameter>
|
|
<type>string</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
プロキシサーバーを示す URI (例:
|
|
<literal>tcp://proxy.example.com:5100</literal>)。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.request-fulluri">
|
|
<term>
|
|
<parameter>request_fulluri</parameter>
|
|
<type>bool</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
&true; を指定すると、リクエストを生成する際に完全な URI
|
|
(例: <literal>GET http://www.example.com/path/to/file.html HTTP/1.0</literal>)
|
|
が用いられます。これは標準のリクエストフォーマットではありませんが、
|
|
このようなフォーマットを要求するプロキシサーバーも存在します。
|
|
</para>
|
|
<para>
|
|
デフォルトは &false; です。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.follow-location">
|
|
<term>
|
|
<parameter>follow_location</parameter>
|
|
<type>int</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
<literal>Location</literal> のリダイレクトをたどります。
|
|
<literal>0</literal> で無効にできます。
|
|
</para>
|
|
<para>
|
|
デフォルトは <literal>1</literal> です。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.max-redirects">
|
|
<term>
|
|
<parameter>max_redirects</parameter>
|
|
<type>int</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
リダイレクトをたどる最大数。値が <literal>1</literal> 以下の場合は
|
|
リダイレクトをたどらないことを意味します。
|
|
</para>
|
|
<para>
|
|
デフォルトは <literal>20</literal> です。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.protocol-version">
|
|
<term>
|
|
<parameter>protocol_version</parameter>
|
|
<type>float</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
HTTP プロトコルのバージョン。
|
|
</para>
|
|
<para>
|
|
PHP 8.0.0 以降では、デフォルトは <literal>1.1</literal> です。
|
|
それより前のバージョンでは、デフォルトは <literal>1.0</literal> でした。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.timeout">
|
|
<term>
|
|
<parameter>timeout</parameter>
|
|
<type>float</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
読み込みタイムアウト秒数を <type>float</type> (例
|
|
<literal>10.5</literal>) で指定します。
|
|
</para>
|
|
<para>
|
|
デフォルトでは &php.ini; 設定
|
|
<link linkend="ini.default-socket-timeout">default_socket_timeout</link>
|
|
の値を使用します。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry xml:id="context.http.ignore-errors">
|
|
<term>
|
|
<parameter>ignore_errors</parameter>
|
|
<type>bool</type>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
ステータスコードが失敗を意味する場合でもコンテンツを取得します。
|
|
</para>
|
|
<para>
|
|
デフォルトは &false; です。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1><!-- }}} -->
|
|
|
|
|
|
<refsect1 role="examples"><!-- {{{ -->
|
|
&reftitle.examples;
|
|
<para>
|
|
<example xml:id="context.http.example-post"><!-- {{{ -->
|
|
<title>ページの取得と POST データの送信</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$postdata = http_build_query(
|
|
[
|
|
'var1' => 'some content',
|
|
'var2' => 'doh',
|
|
]
|
|
);
|
|
|
|
$opts = [
|
|
'http' => [
|
|
'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);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example><!-- }}} -->
|
|
</para>
|
|
<para>
|
|
<example xml:id="context.http.example-fetch-ignore-redirect"><!-- {{{ -->
|
|
<title>リダイレクトを無視し、ヘッダとコンテンツの取得</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$url = "http://www.example.org/header.php";
|
|
|
|
$opts = [
|
|
'http' => [
|
|
'method' => 'GET',
|
|
'max_redirects' => '0',
|
|
'ignore_errors' => '1',
|
|
]
|
|
];
|
|
|
|
$context = stream_context_create($opts);
|
|
$stream = fopen($url, 'r', false, $context);
|
|
|
|
// ヘッダ情報およびストリームのメタデータ
|
|
var_dump(stream_get_meta_data($stream));
|
|
|
|
// $url の実際のデータ
|
|
var_dump(stream_get_contents($stream));
|
|
fclose($stream);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example><!-- }}} -->
|
|
</para>
|
|
</refsect1><!-- }}} -->
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<title>基盤となるソケットストリームのコンテキストオプション</title>
|
|
<simpara>
|
|
これ以外のコンテキストオプションが
|
|
<link linkend="transports.inet">基盤となるトランスポート</link>
|
|
でサポートされています。
|
|
<literal>http://</literal> ストリームの場合は、<literal>tcp://</literal>
|
|
のコンテキストオプションを参照ください。
|
|
<literal>https://</literal> ストリームの場合は、<literal>ssl://</literal>
|
|
のコンテキストオプションを参照ください。
|
|
</simpara>
|
|
</note>
|
|
<note>
|
|
<title>HTTP ステータスライン</title>
|
|
<simpara>
|
|
このストリームラッパーがリダイレクトをたどると、
|
|
<function>stream_get_meta_data</function> が返す
|
|
<literal>wrapper_data</literal> のインデックス <literal>0</literal>
|
|
の内容が必ずしもそのコンテンツの HTTP ステータスラインであるとは限らなくなります。
|
|
</simpara>
|
|
<screen>
|
|
<![CDATA[
|
|
array (
|
|
'wrapper_data' =>
|
|
array (
|
|
0 => 'HTTP/1.0 301 Moved Permanently',
|
|
1 => 'Cache-Control: no-cache',
|
|
2 => 'Connection: close',
|
|
3 => 'Location: http://example.com/foo.jpg',
|
|
4 => 'HTTP/1.1 200 OK',
|
|
...
|
|
]]>
|
|
</screen>
|
|
<simpara>
|
|
最初のリクエストが <literal>301</literal> (permanent redirect)
|
|
を返したので、ストリームラッパーが自動的にリダイレクト先をたどり、レスポンス
|
|
<literal>200</literal> (インデックス = <literal>4</literal>)
|
|
を取得しました。
|
|
</simpara>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><xref linkend="wrappers.http" /></member>
|
|
<member><xref linkend="context.socket" /></member>
|
|
<member><xref linkend="context.ssl" /></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|
|
|