Home  >  Article  >  Backend Development  >  php http_build_query stream_context_create post request

php http_build_query stream_context_create post request

不言
不言Original
2018-07-04 14:17:112092browse

This article mainly introduces the http_build_query stream_context_create post request about php. It has certain reference value. Now I share it with everyone. Friends in need can refer to it.

 1 <?php 
 2 function send_post($url, $post_data) 
 3 { 
 4     $postdata = http_build_query($post_data); 
 5     $options = array( 
 6         &#39;http&#39; => array( 
 7             &#39;method&#39; => &#39;POST&#39;, 
 8             &#39;header&#39; => &#39;Content-type:application/x-www-form-urlencoded&#39;, 
 9             &#39;content&#39; => $postdata,
 10             &#39;timeout&#39; => 15 * 60 // 超时时间(单位:s)
 11         )
 12     );
 13     $context = stream_context_create($options);
 14     $result = file_get_contents($url, false, $context);
 15 
 16     echo $result;
 17 }
 18 
 19 //使用方法
 20 $post_data = array(
 21     &#39;a&#39; => &#39;11&#39;,
 22     &#39;b&#39; => &#39;22&#39;
 23 );
 24 send_post(&#39;http://localhost/b.php&#39;, $post_data);

The above is the entire content of this article. I hope It will be helpful for everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to using openssl to replace mcrypt in PHP7.1

How to import data from PHP Excel to MySQL database

The above is the detailed content of php http_build_query stream_context_create post request. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn