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

 

相关文章:

  • 2021-10-22
  • 2022-12-23
  • 2021-07-09
  • 2021-06-11
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2021-10-01
  • 2022-01-30
  • 2021-11-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案