码迷,mamicode.com
首页 > Web开发 > 详细

PHP http(file_get_content) GET与POST请求方式

时间:2016-08-29 17:31:47      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

1.GET方式请求

<?php  
  
       $data = array(‘sParam1‘=>‘test1‘,‘sParam2‘=>101,‘isAuto‘=>1);  //定义参数  
  
       $data = @http_build_query($data);  //把参数转换成URL数据  
  
       $aContext = array(‘http‘ => array(‘method‘ => ‘GET‘,  
  
                                                                 ‘header‘  => ‘Content-type: application/x-www-form-urlencoded‘,  
  
                                                                 ‘content‘ => $data ));  
  
       $cxContext  = stream_context_create($aContext);  
  
       $sUrl = ‘http://www.mytest.com/test.php‘; //此处必须为完整路径  
  
       $d = @file_get_contents($sUrl,false,$cxContext);  
  
       print_r($d);  
  
?>  

2.POST方式请求

<?php  
  
       $data = array(‘sParam1‘=>‘test1‘,‘sParam2‘=>101,‘isAuto‘=>1);  //定义参数  
  
       $data = @http_build_query($data);  //把参数转换成URL数据  
  
       $aContext = array(‘http‘ => array(‘method‘ => ‘POST‘,  
  
                                                                 ‘header‘  => ‘Content-type: application/x-www-form-urlencoded‘,  
  
                                                                 ‘content‘ => $data ));  
  
       $cxContext  = stream_context_create($aContext);  
  
       $sUrl = ‘http://www.mytest.com/test.php‘; //此处必须为完整路径  
  
       $d = @file_get_contents($sUrl,false,$cxContext);  
  
       print_r($d);  
  
?>  

 

PHP http(file_get_content) GET与POST请求方式

标签:

原文地址:http://www.cnblogs.com/yaoyao1556/p/5818566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!