>  기사  >  백엔드 개발  >  php 的http_build_query stream_context_create post请求

php 的http_build_query stream_context_create post请求

不言
不言원래의
2018-07-04 14:17:111976검색

이 글은 주로 PHP에 관한 http_build_query stream_context_create 게시물 요청을 소개합니다. 이제 여러분과 공유합니다. 도움이 필요한 친구들이 참고할 수 있습니다.

 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);

위 내용이 이 글의 전체 내용이기를 바랍니다. 모든 사람의 학습에 도움이 됩니다. 더 많은 관련 내용을 보려면 PHP 중국어 웹사이트를 주목하세요!

관련 권장 사항:

PHP7.1에서 mcrypt를 대체하기 위해 openssl을 사용하는 방법 소개

PHP Excel에서 MySQL 데이터베이스로 데이터를 가져오는 방법

위 내용은 php 的http_build_query stream_context_create post请求의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:Laravel 학습의 기본다음 기사:Laravel 학습의 기본