PHP put提交和获取数据

原文:http://blog.csdn.net/tracywxh/article/details/8745595

1、下面为模拟提交文件 2.PHP

 

[php] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1. /** 
  2.  *  
  3.  * @param $url 
  4.  * @param $data 
  5.  * @param $method 
  6.  */  
  7. function curlrequest($url,$data,$method='post'){  
  8.     $ch = curl_init(); //初始化CURL句柄   
  9.     curl_setopt($ch, CURLOPT_URL, $url); //设置请求的URL  
  10.     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //设为TRUE把curl_exec()结果转化为字串,而不是直接输出   
  11.     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //设置请求方式  
  12.       
  13.     curl_setopt($ch,CURLOPT_HTTPHEADER,array("X-HTTP-Method-Override: $method"));//设置HTTP头信息  
  14.     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置提交的字符串  
  15.     $document = curl_exec($ch);//执行预定义的CURL   
  16.   
  17.     curl_close($ch);  
  18.       
  19.     return $document;  
  20. }  
  21.   
  22. $url = 'www.wxh.com/3.php';  
  23. $data = "m=1&c=2&jaingxi=67";  
  24. $return = curlrequest($url, $data, 'put');  
  25. var_dump($return);  


2、下面为3.php文件

 

 

[php] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
    1. <?php  
    2.   
    3. $_PUT = array();   
    4. if ('put' == $_SERVER['REQUEST_METHOD']) {   
    5.       
    6. parse_str(file_get_contents('php://input'), $_PUT);  
    7. var_dump($_PUT);  
    8. }   
posted @ 2017-03-16 17:10  叨叨的蜗牛  阅读(509)  评论(0)    收藏  举报