PHP http(file_get_content) GET與POST請求方式


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM