<?xml version="1.0" encoding="UTF-8" ?><oembed><version>1.0</version><provider_name>Чудо{вищные} заметки</provider_name><provider_url>https://miracle.rpz.name</provider_url><author_name>MiRacLe</author_name><author_url>https://miracle.rpz.name/author/miracle/</author_url><title>file_post_contents</title><html>Довольно часто встречающийся вопрос - как средствами php отправить POST запрос (и обработать ответ). И традиционные ответы на этот вопрос:
&lt;ol&gt;
	&lt;li&gt;&lt;a href=&quot;http://php.net/curl&quot;&gt;curl&lt;/a&gt; (самый очевидный ответ, к сожалению не везде доступный)&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://php.net/fsockopen&quot;&gt;fsockopen &lt;/a&gt; (самый распространённый способ)&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://php.net/http&quot;&gt;http&lt;/a&gt; (extension появился сравнительно недавно и советуют его нечасто)&lt;/li&gt;
&lt;/ol&gt;
Спешу поделиться другим способом:
&lt;pre class=&quot;php:nocontrols&quot;&gt; 
$postfields = http_build_query( array (&#039;var1&#039; =&gt; &#039;value 1&#039;, &#039;var2&#039; =&gt; &#039;value 2&#039;,));
$opts = array(&#039;http&#039; =&gt;
   array(
      &#039;method&#039;  =&gt; &#039;POST&#039;,
      &#039;header&#039;  =&gt; &#039;Content-type: application/x-www-form-urlencoded&#039;,
      &#039;content&#039; =&gt; $postfields,
   )
);
$context  = stream_context_create($opts);
$result = file_get_contents(&#039;http://example.com/action.php&#039;, false, $context);
&lt;/pre&gt;
Как видно - не нужны никакие дополнительные extension-ы и в отличии от способа с fsockopen большую часть &quot;грязной&quot; работы возьмёт на себя &lt;a href=&quot;http://php.net/stream_context_create&quot;&gt;stream_context_create&lt;/a&gt;.

Подсмотрено &lt;a href=&quot;http://www.khankennels.com/blog/index.php/archives/2007/09/17/streams-gem/&quot;&gt;вон там&lt;/a&gt;.

P.S.
Название поста глупое, но другого в голову не идёт. ;o)

Technorati Tags: &lt;a href=&quot;http://technorati.com/tag/dev&quot; class=&quot;performancingtags&quot; rel=&quot;tag&quot;&gt;dev&lt;/a&gt;, &lt;a href=&quot;http://technorati.com/tag/php5&quot; class=&quot;performancingtags&quot; rel=&quot;tag&quot;&gt;php5&lt;/a&gt;</html><type>rich</type></oembed>