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

curl 模拟

时间:2017-09-04 13:09:51      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:.com   close   err   init   alt   span   模拟   方式   字符   

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

curl 模拟

标签:.com   close   err   init   alt   span   模拟   方式   字符   

原文地址:http://www.cnblogs.com/hanling/p/7472910.html

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