streams gem

Was reminded today of a gem from the streams extension – sending a POST message and getting its results. We could do it using cURL or sockets – but why work that hard. Being lazy does have its advantages after all.

Now I could make up an example for this – but why when the manual has such a nice one (though it is a bit buried in the manual on the HTTP/HTTPS wrapper page):

[php]
< ?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);

?>
[/php]