HTTP context options
HTTP context options — HTTP context option listing
Description
Context options for http:// and https://
transports.
Options
-
method
string
-
GET, POST, or
any other HTTP method supported by the remote server.
Defaults to GET.
-
Additional headers to be sent during request. Values
in this option will override other values (such as
User-agent:, Host:,
and Authentication:).
-
user_agent
string
-
Value to send with User-Agent: header. This value will
only be used if user-agent is not specified
in the header context option above.
By default the
user_agent
php.ini setting is used.
-
content
string
-
Additional data to be sent after the headers. Typically used
with POST or PUT requests.
-
proxy
string
-
URI specifying address of proxy server. (e.g.
tcp://proxy.example.com:5100).
-
request_fulluri
boolean
-
When set to TRUE, the entire URI will be used when
constructing the request. (i.e.
GET http://www.example.com/path/to/file.html HTTP/1.0).
While this is a non-standard request format, some
proxy servers require it.
Defaults to FALSE.
-
max_redirects
integer
-
The max number of redirects to follow. Value 1 or
less means that no redirects are followed.
Defaults to 20.
-
protocol_version
float
-
HTTP protocol version.
Defaults to 1.0.
-
timeout
float
-
Read timeout in seconds, specified by a float
(e.g. 10.5).
By default the
default_socket_timeout
php.ini setting is used.
-
ignore_errors
boolean
-
Fetch the content even on failure status codes.
Defaults to FALSE
Examples
Example #1 Fetch a page and send POST data
<?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);
?>
Notes
Note:
Underlying socket stream context options
Additional context options may be supported by the
underlying transport
For http:// streams, refer to context
options for the tcp:// transport. For
https:// streams, refer to context options
for the ssl:// transport.