|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<!-- EN-Revision: 3abd17e61d5022d503604cc06894254e3281acf5 Maintainer: lacatoire Status: ready --> |
| 3 | + |
| 4 | +<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"> |
| 5 | + <refnamediv> |
| 6 | + <refname>Opzioni di contesto HTTP</refname> |
| 7 | + <refpurpose>Elenco delle opzioni di contesto HTTP</refpurpose> |
| 8 | + </refnamediv> |
| 9 | + |
| 10 | + <refsect1 role="description"> |
| 11 | + &reftitle.description; |
| 12 | + <para> |
| 13 | + Opzioni di contesto per i trasporti <literal>http://</literal> e <literal>https://</literal>. |
| 14 | + </para> |
| 15 | + </refsect1> |
| 16 | + |
| 17 | + <refsect1 role="options"><!-- {{{ --> |
| 18 | + &reftitle.options; |
| 19 | + <para> |
| 20 | + <variablelist> |
| 21 | + <varlistentry xml:id="context.http.method"> |
| 22 | + <term> |
| 23 | + <parameter>method</parameter> |
| 24 | + <type>string</type> |
| 25 | + </term> |
| 26 | + <listitem> |
| 27 | + <para> |
| 28 | + <constant>GET</constant>, <constant>POST</constant>, o |
| 29 | + qualsiasi altro metodo HTTP supportato dal server remoto. |
| 30 | + </para> |
| 31 | + <para> |
| 32 | + Il valore predefinito è <constant>GET</constant>. |
| 33 | + </para> |
| 34 | + </listitem> |
| 35 | + </varlistentry> |
| 36 | + <varlistentry xml:id="context.http.header"> |
| 37 | + <term> |
| 38 | + <parameter>header</parameter> |
| 39 | + <type>array</type> o <type>string</type> |
| 40 | + </term> |
| 41 | + <listitem> |
| 42 | + <para> |
| 43 | + Intestazioni aggiuntive da inviare durante la richiesta. I valori |
| 44 | + in questa opzione sovrascriveranno altri valori (come |
| 45 | + <literal>User-agent:</literal>, <literal>Host:</literal>, |
| 46 | + e <literal>Authentication:</literal>), |
| 47 | + anche quando si seguono i reindirizzamenti <literal>Location:</literal>. |
| 48 | + Pertanto non è consigliato impostare un'intestazione <literal>Host:</literal>, |
| 49 | + se <parameter>follow_location</parameter> è abilitato. |
| 50 | + </para> |
| 51 | + <para> |
| 52 | + Il valore stringa deve essere costituito da coppie <literal>Chiave: valore</literal> delimitate da |
| 53 | + <literal>\r\n</literal>, ad es. |
| 54 | + <literal>"Content-Type: application/json\r\nConnection: close"</literal>. |
| 55 | + Il valore array deve essere un elenco di coppie <literal>Chiave: valore</literal>, ad es. |
| 56 | + <literal>["Content-Type: application/json", "Connection: close"]</literal>. |
| 57 | + </para> |
| 58 | + </listitem> |
| 59 | + </varlistentry> |
| 60 | + <varlistentry xml:id="context.http.user-agent"> |
| 61 | + <term> |
| 62 | + <parameter>user_agent</parameter> |
| 63 | + <type>string</type> |
| 64 | + </term> |
| 65 | + <listitem> |
| 66 | + <para> |
| 67 | + Valore da inviare con l'intestazione <literal>User-Agent:</literal>. Questo valore verrà |
| 68 | + utilizzato solo se user-agent <emphasis>non</emphasis> è specificato |
| 69 | + nell'opzione di contesto <literal>header</literal> sopra indicata. |
| 70 | + </para> |
| 71 | + <para> |
| 72 | + Per impostazione predefinita viene utilizzata l'impostazione |
| 73 | + <link linkend="ini.user-agent">user_agent</link> |
| 74 | + del &php.ini;. |
| 75 | + </para> |
| 76 | + </listitem> |
| 77 | + </varlistentry> |
| 78 | + <varlistentry xml:id="context.http.content"> |
| 79 | + <term> |
| 80 | + <parameter>content</parameter> |
| 81 | + <type>string</type> |
| 82 | + </term> |
| 83 | + <listitem> |
| 84 | + <para> |
| 85 | + Dati aggiuntivi da inviare dopo le intestazioni. Generalmente utilizzato |
| 86 | + con le richieste POST o PUT. |
| 87 | + </para> |
| 88 | + </listitem> |
| 89 | + </varlistentry> |
| 90 | + <varlistentry xml:id="context.http.proxy"> |
| 91 | + <term> |
| 92 | + <parameter>proxy</parameter> |
| 93 | + <type>string</type> |
| 94 | + </term> |
| 95 | + <listitem> |
| 96 | + <para> |
| 97 | + URI che specifica l'indirizzo del server proxy (ad es. |
| 98 | + <literal>tcp://proxy.example.com:5100</literal>). |
| 99 | + </para> |
| 100 | + </listitem> |
| 101 | + </varlistentry> |
| 102 | + <varlistentry xml:id="context.http.request-fulluri"> |
| 103 | + <term> |
| 104 | + <parameter>request_fulluri</parameter> |
| 105 | + <type>bool</type> |
| 106 | + </term> |
| 107 | + <listitem> |
| 108 | + <para> |
| 109 | + Quando impostato a &true;, l'intero URI verrà utilizzato nella |
| 110 | + costruzione della richiesta (ad es. |
| 111 | + <literal>GET http://www.example.com/path/to/file.html HTTP/1.0</literal>). |
| 112 | + Sebbene questo sia un formato di richiesta non standard, alcuni |
| 113 | + server proxy lo richiedono. |
| 114 | + </para> |
| 115 | + <para> |
| 116 | + Il valore predefinito è &false;. |
| 117 | + </para> |
| 118 | + </listitem> |
| 119 | + </varlistentry> |
| 120 | + <varlistentry xml:id="context.http.follow-location"> |
| 121 | + <term> |
| 122 | + <parameter>follow_location</parameter> |
| 123 | + <type>int</type> |
| 124 | + </term> |
| 125 | + <listitem> |
| 126 | + <para> |
| 127 | + Segue i reindirizzamenti dell'intestazione <literal>Location</literal>. Impostare a |
| 128 | + <literal>0</literal> per disabilitare. |
| 129 | + </para> |
| 130 | + <para> |
| 131 | + Il valore predefinito è <literal>1</literal>. |
| 132 | + </para> |
| 133 | + </listitem> |
| 134 | + </varlistentry> |
| 135 | + <varlistentry xml:id="context.http.max-redirects"> |
| 136 | + <term> |
| 137 | + <parameter>max_redirects</parameter> |
| 138 | + <type>int</type> |
| 139 | + </term> |
| 140 | + <listitem> |
| 141 | + <para> |
| 142 | + Il numero massimo di reindirizzamenti da seguire. Il valore <literal>1</literal> o |
| 143 | + inferiore significa che non vengono seguiti reindirizzamenti. |
| 144 | + </para> |
| 145 | + <para> |
| 146 | + Il valore predefinito è <literal>20</literal>. |
| 147 | + </para> |
| 148 | + </listitem> |
| 149 | + </varlistentry> |
| 150 | + <varlistentry xml:id="context.http.protocol-version"> |
| 151 | + <term> |
| 152 | + <parameter>protocol_version</parameter> |
| 153 | + <type>float</type> |
| 154 | + </term> |
| 155 | + <listitem> |
| 156 | + <para> |
| 157 | + Versione del protocollo HTTP. |
| 158 | + </para> |
| 159 | + <para> |
| 160 | + Il valore predefinito è <literal>1.1</literal> a partire da PHP 8.0.0; |
| 161 | + nelle versioni precedenti il valore predefinito era <literal>1.0</literal>. |
| 162 | + </para> |
| 163 | + </listitem> |
| 164 | + </varlistentry> |
| 165 | + <varlistentry xml:id="context.http.timeout"> |
| 166 | + <term> |
| 167 | + <parameter>timeout</parameter> |
| 168 | + <type>float</type> |
| 169 | + </term> |
| 170 | + <listitem> |
| 171 | + <para> |
| 172 | + Timeout di lettura in secondi, specificato come <type>float</type> |
| 173 | + (ad es. <literal>10.5</literal>). |
| 174 | + </para> |
| 175 | + <para> |
| 176 | + Per impostazione predefinita viene utilizzata l'impostazione |
| 177 | + <link linkend="ini.default-socket-timeout">default_socket_timeout</link> |
| 178 | + del &php.ini;. |
| 179 | + </para> |
| 180 | + </listitem> |
| 181 | + </varlistentry> |
| 182 | + <varlistentry xml:id="context.http.ignore-errors"> |
| 183 | + <term> |
| 184 | + <parameter>ignore_errors</parameter> |
| 185 | + <type>bool</type> |
| 186 | + </term> |
| 187 | + <listitem> |
| 188 | + <para> |
| 189 | + Recupera il contenuto anche in caso di codici di stato di errore. |
| 190 | + </para> |
| 191 | + <para> |
| 192 | + Il valore predefinito è &false;. |
| 193 | + </para> |
| 194 | + </listitem> |
| 195 | + </varlistentry> |
| 196 | + </variablelist> |
| 197 | + </para> |
| 198 | + </refsect1><!-- }}} --> |
| 199 | + |
| 200 | + <refsect1 role="examples"><!-- {{{ --> |
| 201 | + &reftitle.examples; |
| 202 | + <para> |
| 203 | + <example xml:id="context.http.example-post"><!-- {{{ --> |
| 204 | + <title>Recuperare una pagina e inviare dati POST</title> |
| 205 | + <programlisting role="php"> |
| 206 | +<![CDATA[ |
| 207 | +<?php |
| 208 | +
|
| 209 | +$postdata = http_build_query( |
| 210 | + [ |
| 211 | + 'var1' => 'some content', |
| 212 | + 'var2' => 'doh', |
| 213 | + ] |
| 214 | +); |
| 215 | +
|
| 216 | +$opts = [ |
| 217 | + 'http' => [ |
| 218 | + 'method' => 'POST', |
| 219 | + 'header' => 'Content-type: application/x-www-form-urlencoded', |
| 220 | + 'content' => $postdata, |
| 221 | + ] |
| 222 | +]; |
| 223 | +
|
| 224 | +$context = stream_context_create($opts); |
| 225 | +
|
| 226 | +$result = file_get_contents('http://example.com/submit.php', false, $context); |
| 227 | +
|
| 228 | +?> |
| 229 | +]]> |
| 230 | + </programlisting> |
| 231 | + </example><!-- }}} --> |
| 232 | + </para> |
| 233 | + <para> |
| 234 | + <example xml:id="context.http.example-fetch-ignore-redirect"><!-- {{{ --> |
| 235 | + <title>Ignorare i reindirizzamenti ma recuperare intestazioni e contenuto</title> |
| 236 | + <programlisting role="php"> |
| 237 | +<![CDATA[ |
| 238 | +<?php |
| 239 | +
|
| 240 | +$url = "http://www.example.org/header.php"; |
| 241 | +
|
| 242 | +$opts = [ |
| 243 | + 'http' => [ |
| 244 | + 'method' => 'GET', |
| 245 | + 'max_redirects' => '0', |
| 246 | + 'ignore_errors' => '1', |
| 247 | + ] |
| 248 | +]; |
| 249 | +
|
| 250 | +$context = stream_context_create($opts); |
| 251 | +$stream = fopen($url, 'r', false, $context); |
| 252 | +
|
| 253 | +// informazioni sulle intestazioni e metadati |
| 254 | +// dello stream |
| 255 | +var_dump(stream_get_meta_data($stream)); |
| 256 | +
|
| 257 | +// dati effettivi all'URL $url |
| 258 | +var_dump(stream_get_contents($stream)); |
| 259 | +fclose($stream); |
| 260 | +?> |
| 261 | +]]> |
| 262 | + </programlisting> |
| 263 | + </example><!-- }}} --> |
| 264 | + </para> |
| 265 | + </refsect1><!-- }}} --> |
| 266 | + |
| 267 | + <refsect1 role="notes"> |
| 268 | + &reftitle.notes; |
| 269 | + <note> |
| 270 | + <title>Opzioni di contesto del socket sottostante</title> |
| 271 | + <simpara> |
| 272 | + Opzioni di contesto aggiuntive possono essere supportate dal |
| 273 | + <link linkend="transports.inet">trasporto sottostante</link>. |
| 274 | + Per gli stream <literal>http://</literal>, fare riferimento alle opzioni |
| 275 | + di contesto per il trasporto <literal>tcp://</literal>. Per gli |
| 276 | + stream <literal>https://</literal>, fare riferimento alle opzioni di contesto |
| 277 | + per il trasporto <literal>ssl://</literal>. |
| 278 | + </simpara> |
| 279 | + </note> |
| 280 | + <note> |
| 281 | + <title>Riga di stato HTTP</title> |
| 282 | + <simpara> |
| 283 | + Quando questo wrapper dello stream segue un reindirizzamento, il |
| 284 | + <literal>wrapper_data</literal> restituito da |
| 285 | + <function>stream_get_meta_data</function> potrebbe non contenere necessariamente |
| 286 | + la riga di stato HTTP che si applica effettivamente ai dati del contenuto all'indice |
| 287 | + <literal>0</literal>. |
| 288 | + </simpara> |
| 289 | + <screen> |
| 290 | +<![CDATA[ |
| 291 | +array ( |
| 292 | + 'wrapper_data' => |
| 293 | + array ( |
| 294 | + 0 => 'HTTP/1.0 301 Moved Permanently', |
| 295 | + 1 => 'Cache-Control: no-cache', |
| 296 | + 2 => 'Connection: close', |
| 297 | + 3 => 'Location: http://example.com/foo.jpg', |
| 298 | + 4 => 'HTTP/1.1 200 OK', |
| 299 | + ... |
| 300 | +]]> |
| 301 | + </screen> |
| 302 | + <simpara> |
| 303 | + La prima richiesta ha restituito un <literal>301</literal> (reindirizzamento permanente), |
| 304 | + quindi il wrapper dello stream ha seguito automaticamente il reindirizzamento per ottenere una |
| 305 | + risposta <literal>200</literal> (indice = <literal>4</literal>). |
| 306 | + </simpara> |
| 307 | + </note> |
| 308 | + </refsect1> |
| 309 | + |
| 310 | + <refsect1 role="seealso"> |
| 311 | + &reftitle.seealso; |
| 312 | + <para> |
| 313 | + <simplelist> |
| 314 | + <member><xref linkend="wrappers.http" /></member> |
| 315 | + <member><xref linkend="context.socket" /></member> |
| 316 | + <member><xref linkend="context.ssl" /></member> |
| 317 | + </simplelist> |
| 318 | + </para> |
| 319 | + </refsect1> |
| 320 | + |
| 321 | +</refentry> |
| 322 | + |
| 323 | +<!-- Keep this comment at the end of the file |
| 324 | +Local variables: |
| 325 | +mode: sgml |
| 326 | +sgml-omittag:t |
| 327 | +sgml-shorttag:t |
| 328 | +sgml-minimize-attributes:nil |
| 329 | +sgml-always-quote-attributes:t |
| 330 | +sgml-indent-step:1 |
| 331 | +sgml-indent-data:t |
| 332 | +indent-tabs-mode:nil |
| 333 | +sgml-parent-document:nil |
| 334 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 335 | +sgml-exposed-tags:nil |
| 336 | +sgml-local-catalogs:nil |
| 337 | +sgml-local-ecat-files:nil |
| 338 | +End: |
| 339 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 340 | +vim: et tw=78 syn=sgml |
| 341 | +vi: ts=1 sw=1 |
| 342 | +--> |
0 commit comments