add example on how to send POST data using stream context opts. many thanks to Sara for the code

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@218006 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Nuno Lopes 2006-08-11 22:00:05 +00:00
parent 714608859f
commit 6b8f6fedcd

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.61 $ -->
<!-- $Revision: 1.62 $ -->
<appendix id="wrappers">
<title>List of Supported Protocols/Wrappers</title>
<para>
@ -202,6 +202,35 @@ foreach($meta_data['wrapper_data'] as $response) {
]]>
</programlisting>
</informalexample>
<example>
<title>Fetch a page and send POST data</title>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
</example>
<simpara>
The stream allows access to the <emphasis>body</emphasis> of
the resource; the headers are stored in the