📄 context.http.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>HTTP context option listing</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="context.socket.html">Socket context options</a></div> <div class="next" style="text-align: right; float: right;"><a href="context.ftp.html">FTP context options</a></div> <div class="up"><a href="context.html">Context options and parameters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="context.http" class="refentry"> <div class="refnamediv"> <h1 class="refname">HTTP context options</h1> <p class="refpurpose"><span class="refname">HTTP context options</span> — <span class="dc-title">HTTP context option listing</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <p class="para"> Context options for <i>http://</i> and <i>https://</i> transports. </p> </div> <div class="refsect1 options"> <h3 class="title">Options</h3> <p class="para"> <dl> <dt id="context.http.method"> <span class="term"> <i><tt class="parameter">method</tt></i> <a href="language.types.string.html" class="type string">string</a> </span> <dd> <p class="para"> <b><tt>GET</tt></b>, <b><tt>POST</tt></b>, or any other HTTP method supported by the remote server. </p> <p class="para"> Defaults to <b><tt>GET</tt></b>. </p> </dd> </dt> <dt id="context.http.header"> <span class="term"> <i><tt class="parameter">header</tt></i> <a href="language.types.string.html" class="type string">string</a> </span> <dd> <p class="para"> Additional headers to be sent during request. Values in this option will override other values (such as <i>User-agent:</i>, <i>Host:</i>, and <i>Authentication:</i>). </p> </dd> </dt> <dt id="context.http.user-agent"> <span class="term"> <i><tt class="parameter">user_agent</tt></i> <a href="language.types.string.html" class="type string">string</a> </span> <dd> <p class="para"> Value to send with User-Agent: header. This value will only be used if user-agent is <em class="emphasis">not</em> specified in the <i>header</i> context option above. </p> <p class="para"> By default the <a href="filesystem.configuration.html#ini.user-agent" class="link">user_agent</a> <var class="filename">php.ini</var> setting is used. </p> </dd> </dt> <dt id="context.http.content"> <span class="term"> <i><tt class="parameter">content</tt></i> <a href="language.types.string.html" class="type string">string</a> </span> <dd> <p class="para"> Additional data to be sent after the headers. Typically used with POST or PUT requests. </p> </dd> </dt> <dt id="context.http.proxy"> <span class="term"> <i><tt class="parameter">proxy</tt></i> <a href="language.types.string.html" class="type string">string</a> </span> <dd> <p class="para"> URI specifying address of proxy server. (e.g. <i>tcp://proxy.example.com:5100</i>). </p> </dd> </dt> <dt id="context.http.request-fulluri"> <span class="term"> <i><tt class="parameter">request_fulluri</tt></i> <a href="language.types.boolean.html" class="type boolean">boolean</a> </span> <dd> <p class="para"> When set to <b><tt>TRUE</tt></b>, the entire URI will be used when constructing the request. (i.e. <i>GET http://www.example.com/path/to/file.html HTTP/1.0</i>). While this is a non-standard request format, some proxy servers require it. </p> <p class="para"> Defaults to <b><tt>FALSE</tt></b>. </p> </dd> </dt> <dt id="context.http.max-redirects"> <span class="term"> <i><tt class="parameter">max_redirects</tt></i> <a href="language.types.integer.html" class="type integer">integer</a> </span> <dd> <p class="para"> The max number of redirects to follow. Value <i>1</i> or less means that no redirects are followed. </p> <p class="para"> Defaults to <i>20</i>. </p> </dd> </dt> <dt id="context.http.protocol-version"> <span class="term"> <i><tt class="parameter">protocol_version</tt></i> <a href="language.types.float.html" class="type float">float</a> </span> <dd> <p class="para"> HTTP protocol version. </p> <p class="para"> Defaults to <i>1.0</i>. </p> </dd> </dt> <dt id="context.http.timeout"> <span class="term"> <i><tt class="parameter">timeout</tt></i> <a href="language.types.float.html" class="type float">float</a> </span> <dd> <p class="para"> Read timeout in seconds, specified by a <a href="language.types.float.html" class="type float">float</a> (e.g. <i>10.5</i>). </p> <p class="para"> By default the <a href="filesystem.configuration.html#ini.default-socket-timeout" class="link">default_socket_timeout</a> <var class="filename">php.ini</var> setting is used. </p> </dd> </dt> <dt id="context.http.ignore-errors"> <span class="term"> <i><tt class="parameter">ignore_errors</tt></i> <a href="language.types.boolean.html" class="type boolean">boolean</a> </span> <dd> <p class="para"> Fetch the content even on failure status codes. </p> <p class="para"> Defaults to <b><tt>FALSE</tt></b> </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.3.0</td> <td colspan="1" rowspan="1" align="left"> Added <i><tt class="parameter">ignore_errors</tt></i>. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.2.1</td> <td colspan="1" rowspan="1" align="left"> Added <i><tt class="parameter">timeout</tt></i>. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.1.0</td> <td colspan="1" rowspan="1" align="left"> Added HTTPS proxying through HTTP proxies. </td> <td colspan="1" rowspan="1" align="left">5.1.0</td> <td colspan="1" rowspan="1" align="left"> Added <i><tt class="parameter">max_redirects</tt></i>. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.1.0</td> <td colspan="1" rowspan="1" align="left"> Added <i><tt class="parameter">protocol_version</tt></i>. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="context.http.example-post" name="context.http.example-post"> <p><b>Example #1 Fetch a page and send POST data</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br />$postdata </span><span style="color: #007700">= </span><span style="color: #0000BB">http_build_query</span><span style="color: #007700">(<br /> array(<br /> </span><span style="color: #DD0000">'var1' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'some content'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'var2' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'doh'<br /> </span><span style="color: #007700">)<br />);<br /><br /></span><span style="color: #0000BB">$opts </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'http' </span><span style="color: #007700">=><br /> array(<br /> </span><span style="color: #DD0000">'method' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'POST'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'header' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Content-type: application/x-www-form-urlencoded'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'content' </span><span style="color: #007700">=> </span><span style="color: #0000BB">$postdata<br /> </span><span style="color: #007700">)<br />);<br /><br /></span><span style="color: #0000BB">$context </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(</span><span style="color: #0000BB">$opts</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://example.com/submit.php'</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">, </span><span style="color: #0000BB">$context</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: <b>Underlying socket stream context options</b><br /> <span class="simpara"> Additional context options may be supported by the <a href="transports.html#transports.inet" class="link">underlying transport</a> For <i>http://</i> streams, refer to context options for the <i>tcp://</i> transport. For <i>https://</i> streams, refer to context options for the <i>ssl://</i> transport. </span> </p></blockquote> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="context.socket.html" class="xref">Socket context options</a></li> <li class="member"><a href="context.ssl.html" class="xref">SSL context options</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="context.socket.html">Socket context options</a></div> <div class="next" style="text-align: right; float: right;"><a href="context.ftp.html">FTP context options</a></div> <div class="up"><a href="context.html">Context options and parameters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -